PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
like_duh44
Forum Commoner
Posts: 63 Joined: Sat Jul 26, 2003 6:57 pm
Post
by like_duh44 » Wed Aug 13, 2003 7:17 am
Ok, I have a site (chatroom) that has an included file. This file looks for the user prefs that are saved in a mysql database and puts them into array $mainprefs. No matter what, i'm not getting any values for these even though I tell them to put values if none are present. Why???
Code: Select all
<?php
if ($_GETїtheme] == "")
{
$theme = $mainprefsї1];
}
else
{
$theme = "$_GETїtheme]";
}
if ($_GETїfontcolor] == "")
{
$fontcolor = $mainprefsї2];
}
else
{
$fontcolor = $_GETїfontcolor];
}
if ($_GETїfontbg] == "")
{
$fontbg = $mainprefsї3];
}
else
{
$fontbg = $_GETїfontbg];
}
if ($_GETїbold] == "")
{
$bold = $mainprefsї4];
}
else
{
$bold = $_GETїbold];
}
if ($_GETїitalic] == "")
{
$italic = $mainprefsї5];
}
else
{
$italic = $_GETїitalic];
}
if ($_GETїunderline] == "")
{
$underline = $mainprefsї6];
}
else
{
$underline = $_GETїunderline];
}
?>
Seth_[php.pl]
Forum Commoner
Posts: 30 Joined: Sun Aug 10, 2003 5:25 am
Location: Warsaw / Poland
Post
by Seth_[php.pl] » Wed Aug 13, 2003 7:34 am
First of all use array like this:
$_GET[' fontcolor' ]
Replace $_GET['fontcolor'] == "" with empty( $_GET['fontcolor'] )
do this with other values
P.S. PHP is not a Client-Side script
like_duh44
Forum Commoner
Posts: 63 Joined: Sat Jul 26, 2003 6:57 pm
Post
by like_duh44 » Wed Aug 13, 2003 7:50 am
i did that but to no avail, just get an error about unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
and why did you think I thought it was client side?
Seth_[php.pl]
Forum Commoner
Posts: 30 Joined: Sun Aug 10, 2003 5:25 am
Location: Warsaw / Poland
Post
by Seth_[php.pl] » Wed Aug 13, 2003 8:05 am
it works for me:
Code: Select all
if ( empty( $_GET['theme'] ) )
{
$theme = $mainprefs[1];
}
else
{
$theme = $_GET['theme'];
}
if ( empty( $_GET['fontcolor'] ) )
{
$fontcolor = $mainprefs[2];
}
else
{
$fontcolor = $_GET['fontcolor'];
}
if ( empty( $_GET['fontbg'] ) )
{
$fontbg = $mainprefs[3];
}
else
{
$fontbg = $_GET['fontbg'];
}
if ( empty( $_GET['bold'] ) )
{
$bold = $mainprefs[4];
}
else
{
$bold = $_GET['bold'];
}
if ( empty( $_GET[italic] ) )
{
$italic = $mainprefs[5];
}
else
{
$italic = $_GET['italic'];
}
if ( empty( $_GET['underline'] ) )
{
$underline = $mainprefs[6];
}
else
{
$underline = $_GET['underline'];
}
like_duh44 wrote: and why did you think I thought it was client side?
Becouse this is a Client-side forum
like_duh44
Forum Commoner
Posts: 63 Joined: Sat Jul 26, 2003 6:57 pm
Post
by like_duh44 » Wed Aug 13, 2003 8:15 am
LOL, well, i copy-pasted (I know, i hate doing it, but I want to make sure its right. At least I know what the code is doing
) and still came up with this error:
Fatal error: input in flex scanner failed in /home/virtual/site138/fst/var/www/html/chat/chat_themes on line 1
which means its still now getting the string because its supposed to be
/home/virtual/site138/fst/var/www/html/chat/chat_themes/default_theme.php
or whatever theme the person has in the database
like_duh44
Forum Commoner
Posts: 63 Joined: Sat Jul 26, 2003 6:57 pm
Post
by like_duh44 » Wed Aug 13, 2003 8:17 am
Heres the exact (except for secret data) that is in the file:
Code: Select all
<?php
$server = "localhost";
$database = "vgapws1_myhost24_com";
$user = "symbiosis";
$password = "not shown for security reasons";
$link = mysql_connect($server, $user, $password) or die("Could not connect");
mysql_select_db($database, $link) or die("Could not select database");
$mainquery = "SELECT * FROM `chat_prefs` WHERE `username` = '$_GET[username]'";
$mainresults = mysql_query($mainquery, $link) or die("Main Prefs Query Failed!");
while ($mainrow=mysql_fetch_row($mainresults))
{
$mainprefs[] = $mainrow;
}
if (!eregi("aatachat.php", $_SERVER['PHP_SELF'])) {
if ( empty( $_GET['theme'] ) )
{
$theme = $mainprefs[1];
}
else
{
$theme = $_GET['theme'];
}
if ( empty( $_GET['fontcolor'] ) )
{
$fontcolor = $mainprefs[2];
}
else
{
$fontcolor = $_GET['fontcolor'];
}
if ( empty( $_GET['fontbg'] ) )
{
$fontbg = $mainprefs[3];
}
else
{
$fontbg = $_GET['fontbg'];
}
if ( empty( $_GET['bold'] ) )
{
$bold = $mainprefs[4];
}
else
{
$bold = $_GET['bold'];
}
if ( empty( $_GET[italic] ) )
{
$italic = $mainprefs[5];
}
else
{
$italic = $_GET['italic'];
}
if ( empty( $_GET['underline'] ) )
{
$underline = $mainprefs[6];
}
else
{
$underline = $_GET['underline'];
}
}
if (!eregi("chat_posts.php", $_SERVER['PHP_SELF'])) {
include ("chat_themes/$theme");
echo "<style>";
echo "\n<!--\n";
echo "body { color: $color[6]; background-color: $color[3]}\n";
echo "a { color: $color[8]}\n";
echo "--!>\n";
echo "</style>";
} else {
include ("chat_themes/$theme");
echo "<style>";
echo "\n<!--\n";
echo "body { color: $color[7]; background-color: $color[4]}\n";
echo "a { color: $color[8]}\n";
echo "--!>\n";
echo "</style>";
}
Seth_[php.pl]
Forum Commoner
Posts: 30 Joined: Sun Aug 10, 2003 5:25 am
Location: Warsaw / Poland
Post
by Seth_[php.pl] » Wed Aug 13, 2003 8:18 am
The code I've posted is good so i supose it must be other reason why it dosen't work
like_duh44
Forum Commoner
Posts: 63 Joined: Sat Jul 26, 2003 6:57 pm
Post
by like_duh44 » Wed Aug 13, 2003 8:58 am
I did a test, to see if it was even getting any values from the query. Heres the code:
Code: Select all
<?php
$mainname = $_GET[username];
$server = "localhost";
$database = "vgapws1_myhost24_com";
$user = "symbiosis";
$password = "not shown";
$link = mysql_connect($server, $user, $password) or die("Could not connect");
mysql_select_db($database, $link) or die("Could not select database");
$mainquery = "SELECT * FROM `chat_prefs` WHERE `username` = '$mainname'";
$mainresults = mysql_query($mainquery, $link) or die("Main Prefs Query Failed!");
$mainprefs[] = mysql_fetch_array($mainresults);
mysql_free_result($mainresults);
$theme = $mainprefs[1];
$title = "?username=$mainname&theme=$theme&fontcolor=$mainprefs[2]&fontbg=$mainprefs[3]&bold=$mainprefs[4]&italic=$mainprefs[5]&underline=$mainprefs[6]";
echo "$title";
?>
And all it echoes is :
?username=Doom&theme=&fontcolor=&fontbg=&bold=&italic=&underline=
Seth_[php.pl]
Forum Commoner
Posts: 30 Joined: Sun Aug 10, 2003 5:25 am
Location: Warsaw / Poland
Post
by Seth_[php.pl] » Wed Aug 13, 2003 9:48 am
I think the problem is in:
$mainname = $_GET[username];
Should be:
$mainname = $_GET[' username' ];
Alsow change SQL query:
SELECT * FROM chat_prefs WHERE username = '$mainname'
And check what is the output of your query.