Jump to content

Archived

This topic is now archived and is closed to further replies.

RTS

probably overlooking something stupid

Recommended Posts

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.jpg
style=border-top:3px red solid;border-bottom:3px red
solid;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?

Share this post


Link to post
Share on other sites
for one thing:

die('Could not connect: '. mysql_error());

notice the ' '

also

$result = mysql_query("SELECT about FROM users WHERE username = '$user'");

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.jpg
style=border-top:3px red solid;border-bottom:3px red
solid;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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
but do I replace this with what you said? [code]$sql = "SELECT about FROM users WHERE username = $user";
$result = mysql_query($sql);[/code]

Share this post


Link to post
Share on other sites
well, i found something interesting. if $user = a number, then it works, but if it is letters, then it wont. any thoughts?

Share this post


Link to post
Share on other sites
'$user' not $user - trust me  ;D

Try 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]

Share this post


Link to post
Share on other sites
no, that  didnt work, atleast before it did what I wanted with numbers as $user. that just gives me a parse error.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.