lilbadger25 Posted January 25, 2008 Share Posted January 25, 2008 I have a form that is populated with information from a mysql table with intentions to edit the copy. When I click the "update" button to update the copy, I get Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/sites/site19/eventsEdit.php on line 32 Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/sites/site19/eventsEdit.php on line 33 Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/sites/site19/eventsEdit.php on line 34 Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/sites/site19/eventsEdit.php on line 35 Can someone explain why this is happening? Lines 28-36 (the erroring lines are $id to $eventImage) <?php mysql_select_db($database, $Site); $query = "SELECT * FROM events WHERE eventID = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); $id = mysql_result($result,$i,"eventID"); $eventTitle = mysql_result($result,$i,"eventTitle"); $eventInfo = mysql_result($result,$i,"eventInfo"); $eventImage = mysql_result($result,$i,"eventImage"); ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2008 Share Posted January 25, 2008 mysql_result() in addition to being the slowest way of fetching information from a result set has the unfortunate problem of generating an error when there are zero rows in the result set. You should use the mysql_num_rows() function to check if there are any rows in the result set before your attempt access the data or you should use one of the mysql_fetch_xxxxxx() functions instead. They simply return a FALSE value when there are zero rows in the result set and don't generate that error. They are also faster because they fetch a whole row at one time. Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted January 25, 2008 Share Posted January 25, 2008 does $i actually have a value? based on the errors output I'm guessing not. Personally I don't like querying like this, try this alternative: <?php mysql_select_db($database, $Site); $query = "SELECT * FROM events WHERE eventID = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_object($result); $id = $row->eventID; $eventTitle = $row->eventTitle; $eventInfo = $row->eventInfo; $eventImage = $row->eventImage; } else { // Query was empty } ?> Quote Link to comment Share on other sites More sharing options...
lilbadger25 Posted January 25, 2008 Author Share Posted January 25, 2008 PFMaBiSmAd, thanks for the explaination. I had read somewhere on the internet that mysql_num_rows() was a better function to use, but it wasn't explained as to why. PHP Monkeh, that fixed me up. Thanks Quote Link to comment 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.