Jump to content

Recommended Posts

Hey everyone,

 

I have some code which is really giving me some grief. The script always dies at this exact point, giving me the same errors over and over. Shown first is the offending snippet, followed by the errors.

$result=mysql_query("select currentcar, currenthome from progress where userid = $userid;");
while($result=mysql_fetch_array($result))
        {
		$carpurchased = $result["currentcar"]; 
		$homepurchased = $result["currenthome"];
	}

 

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.joliet/blah/blah.org/main/updatehomequestions.php on line 20

 

Warning: Cannot modify header information - headers already sent by (output started at /home/.joliet/blah/blah.org/main/updatehomequestions.php:7) in /home/.joliet/blah/blah.org/main/updatehomequestions.php on line 38

 

Now, i know that the most common cause of the first error is a typo in the database connecting code. I've checked that. There are no typos. I can hit the database perfectly if i hard code and then echo the $userid. Neither field is empty either. Is there a mistake in the snippet? I know that sometimes if you work on something too long you can miss the obvious. Any help or suggestions would be a godsend!

 

Thanks!

two things.  first off, you have an erroneous semi colon at the end of the query, which is unnecessary when passing the query to mysql_query():

 

$result=mysql_query("select currentcar, currenthome from progress where userid = $userid");

 

second, this code will only work for the first row.  in the while() loop, you're overwriting the $result variable (which contains the resource ID of the query's results) with the first row; when it runs the second time, you're going to get an invalid resource error as well.  change $result to anything else in the while:

 

while($anything_else=mysql_fetch_array($result))

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.