Jump to content

probably overlooking something stupid


RTS

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?
Link to comment
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.
Link to comment
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.
Link to comment
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]
Link to comment
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?
Link to comment
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]
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.