I keep getting this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on first line of this code: The code is: $sql = "select * from sponsored_jokes where jokeid = $jokeid"; $result = mysql_query($sql ,$db); if ($myrow = mysql_fetch_array($result)) { do { $sponsorid = $myrow["sponsorid"]; } while ($myrow = mysql_fetch_array($result)); } Code (markup): It worked fine on PHP4. Now it does not on PHP5. Please help. Thank you.
Add this after the mysql_query() line: (It should show us the error message) if (!$result) { die('Invalid query: ' . mysql_error()); } PHP:
Thank you. I get these: Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
I think the syntax is correct but it looks better like this: $sql = "SELECT * FROM sponsored_jokes WHERE jokeid = $jokeid"; PHP: Most importantly, Is $jokeid null?
Well, where are you getting $jokeid from? Where is it initialized? Shouldn't it be $_GET['jokeid']? (be sure to use mysql_real_escape_string($_GET['jokeid']) in your SQL)
even when I write $sql = "select * from sponsored_jokes where jokeid = 2"; i still get that error instead of displaying joke number 2
Try: $sql = "SELECT * FROM `sponsored_jokes` WHERE `jokeid` = '$jokeid'"; $result = mysql_query($sql, $db) or die(mysql_error()); if ($myrow = mysql_fetch_array($result)) { do { $sponsorid = $myrow["sponsorid"]; } while ($myrow = mysql_fetch_array($result)); } Code (markup):
$sponsorid is empty? $sql = "SELECT * FROM `sponsored_jokes` WHERE `jokeid` = '$jokeid'"; $result = mysql_query($sql, $db) or die(mysql_error()); while($myrow = mysql_fetch_array($result)){ $sponsorid = $myrow["sponsorid"]; } Code (markup): Not liking the do thing.
Still not working.... thank you anyway! It seems the script can't access the db correctly.... however it does access it..but only partially.