Pandolfo Posted August 31, 2007 Share Posted August 31, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/67449-solved-going-nutsfresh-set-of-eyes-anyone/ Share on other sites More sharing options...
tibberous Posted August 31, 2007 Share Posted August 31, 2007 Might be that your query is failing, then your sending the junk query into mysql_fetch_array. Right after your query line, echo mysql_error(); Might be something simple, like $userid not getting set. Quote Link to comment https://forums.phpfreaks.com/topic/67449-solved-going-nutsfresh-set-of-eyes-anyone/#findComment-338592 Share on other sites More sharing options...
akitchin Posted August 31, 2007 Share Posted August 31, 2007 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)) Quote Link to comment https://forums.phpfreaks.com/topic/67449-solved-going-nutsfresh-set-of-eyes-anyone/#findComment-338594 Share on other sites More sharing options...
Pandolfo Posted August 31, 2007 Author Share Posted August 31, 2007 Perfect! Awesome! Kick-&#*! Thank you so much! You rock! Quote Link to comment https://forums.phpfreaks.com/topic/67449-solved-going-nutsfresh-set-of-eyes-anyone/#findComment-338601 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.