Jump to content

[SOLVED] Errors when trying to update db info


lilbadger25

Recommended Posts

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");
?>

 

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.

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

}

?>

Archived

This topic is now archived and is closed to further replies.

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