RTS Posted August 25, 2006 Share Posted August 25, 2006 I am getting this error [code]Parse error: parse error in /Library/WebServer/Documents/users/10.php on line 12[/code] for this code [code]<html><body><title>Profile</title><body bgcolor=336699><div align=center><table width=332 cellpadding=0 cellspacing=3><tr><td background=tableo.jpgstyle=border-top:3px red solid;border-bottom:3px redsolid;border-right:36px red solid;border-left:3px red solid;><?php$user = 10;$con = @mysql_connect("localhost", "ZackBabtkis", "");if (!$con) { die(Could not connect: . mysql_error()); }mysql_select_db(test, $con);$result = mysql_query(SELECT about FROM users WHERE username = $user);while($row = mysql_fetch_array($result)) { echo $row[about]; }mysql_close($con);?></td></tr></table></body></html>[/code]Any ideas about whats wrong? Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/ Share on other sites More sharing options...
.josh Posted August 25, 2006 Share Posted August 25, 2006 for one thing:die('Could not connect: '. mysql_error());notice the ' 'also $result = mysql_query("SELECT about FROM users WHERE username = '$user'"); Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80169 Share on other sites More sharing options...
RTS Posted August 25, 2006 Author Share Posted August 25, 2006 okay, the page loads now, but in the table in the middle I get "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Library/WebServer/Documents/users/and4.php on line 11" Im still using basicly the same code as above. Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80175 Share on other sites More sharing options...
AndyB Posted August 25, 2006 Share Posted August 25, 2006 Good error trapping and reporting will simplify your coding endeavours.Change:[code]$result = mysql_query(SELECT about FROM users WHERE username = $user);[/code]To this:[code]$query = SELECT about FROM users WHERE username = '$user'";$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // what's wrong?[/code]Report the full error message. Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80184 Share on other sites More sharing options...
RTS Posted August 25, 2006 Author Share Posted August 25, 2006 that gives me "Parse error: parse error in /Library/WebServer/Documents/users/9.php on line 11" again. it could be that my code has changed. this is what it looked like before I made the change you suggested.[code=php:0]<html><body><title>Profile</title><body bgcolor=336699><div align=center><table width=332 cellpadding=0 cellspacing=3><tr><td background=tableo.jpgstyle=border-top:3px red solid;border-bottom:3px redsolid;border-right:36px red solid;border-left:3px red solid;><?php$user = 10;$con = mysql_connect( "localhost", "ZackBabtkis", "") or die(mysql_error());mysql_select_db(test, $con);$sql = "SELECT about FROM users WHERE username = $user";$result = mysql_query($sql);while($row = mysql_fetch_array($result)) { print($row[about]);}mysql_close($con);?></td></tr></table></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80189 Share on other sites More sharing options...
AndyB Posted August 25, 2006 Share Posted August 25, 2006 How about making the change I suggested, uploading it to your server, running it and identifying both the error you get as well as telling us which line of code has the parse error ... and posting at least a handful of lines including that one? Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80190 Share on other sites More sharing options...
RTS Posted August 25, 2006 Author Share Posted August 25, 2006 but do I replace this with what you said? [code]$sql = "SELECT about FROM users WHERE username = $user";$result = mysql_query($sql);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80191 Share on other sites More sharing options...
RTS Posted August 26, 2006 Author Share Posted August 26, 2006 well, i found something interesting. if $user = a number, then it works, but if it is letters, then it wont. any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80536 Share on other sites More sharing options...
AndyB Posted August 26, 2006 Share Posted August 26, 2006 '$user' not $user - trust me ;DTry replacing the line you use with code like the two lines I suggested several posts ago.[code]$sql = "SELECT about FROM users WHERE username = '$user'";$result = mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $query); // what's wrong?[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80539 Share on other sites More sharing options...
RTS Posted August 26, 2006 Author Share Posted August 26, 2006 no, that didnt work, atleast before it did what I wanted with numbers as $user. that just gives me a parse error. Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80549 Share on other sites More sharing options...
AndyB Posted August 26, 2006 Share Posted August 26, 2006 [quote author=RTS link=topic=105560.msg422178#msg422178 date=1156558135]no, that didnt work, atleast before it did what I wanted with numbers as $user. that just gives me a parse error.[/quote]Please post the actual code you are using. When something "doesn't work" explain what it doesn't do that you expected it to do. When you get a parse error and nobody knows what the full code is, it's just guesswork trying to help. Even if the complete code is posted, telling us which line the parse error relates to will help (and the given line number is NOT necessarily the line with the erro). Since I copied my code suggestion direct from working code, I doubt that it's the source of any parse error. Quote Link to comment https://forums.phpfreaks.com/topic/18607-probably-overlooking-something-stupid/#findComment-80552 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.