Jump to content


Photo

probably overlooking something stupid


  • Please log in to reply
10 replies to this topic

#1 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 25 August 2006 - 02:50 AM

I am getting this error
Parse error: parse error in /Library/WebServer/Documents/users/10.php on line 12
for this 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>
Any ideas about whats wrong?

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 August 2006 - 03:23 AM

for one thing:

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

notice the ' '

also

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

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 25 August 2006 - 03:40 AM

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.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 25 August 2006 - 04:23 AM

Good error trapping and reporting will simplify your coding endeavours.

Change:
$result = mysql_query(SELECT about FROM users WHERE username = $user);

To this:
$query = SELECT about FROM users WHERE username = '$user'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // what's wrong?

Report the full error message.
Legend has it that reading the manual never killed anyone.
My site

#5 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 25 August 2006 - 04:49 AM

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.
<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>


#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 25 August 2006 - 04:59 AM

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?
Legend has it that reading the manual never killed anyone.
My site

#7 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 25 August 2006 - 05:02 AM

but do I replace this with what you said?
$sql = "SELECT about FROM users WHERE username = $user";
$result = mysql_query($sql);


#8 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 26 August 2006 - 01:24 AM

well, i found something interesting. if $user = a number, then it works, but if it is letters, then it wont. any thoughts?

#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 August 2006 - 01:34 AM

'$user' not $user - trust me  ;D

Try replacing the line you use with code like the two lines I suggested several posts ago.

$sql = "SELECT about FROM users WHERE username = '$user'";
$result = mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $query); // what's wrong?

Legend has it that reading the manual never killed anyone.
My site

#10 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 26 August 2006 - 02:08 AM

no, that  didnt work, atleast before it did what I wanted with numbers as $user. that just gives me a parse error.

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 August 2006 - 02:17 AM

no, that  didnt work, atleast before it did what I wanted with numbers as $user. that just gives me a parse error.


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.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users