neverforget98 Posted November 15, 2013 Share Posted November 15, 2013 Hello, On one of the pages of the system I am coding there is a form to update the destination of one of the rows. Every row that has no destination has a form to update the destination. However, when you update the destination it updates it for every row that doesn't have a destination. This is the portion of the code, thanks: if($destination=='') { echo "<form method='post'> <td width='25%'><center><input type='text' name='destination_save2' placeholder='Destination Location' /><input type='submit' name='submit2' value='Update Call' /></center></td>"; if(isset($_POST['submit2'])) { $destination_save2=$_POST['destination_save2']; $result8=mysql_query("UPDATE uc_calls SET destination='$destination_save2' WHERE id=$id"); if(!$result8) { die('Failed to update call. Please contact your Technical Analyst with this error:<br />' .mysql_error()); } else { header("Location: ?"); } } echo "</form>"; } else { echo "<td width='25%'><center>$destination</center></td>"; } Link to comment https://forums.phpfreaks.com/topic/283934-updating-too-many-rows/ Share on other sites More sharing options...
Ch0cu3r Posted November 15, 2013 Share Posted November 15, 2013 Is this code being ran in a loop? if it is then it'll update every row to the same destination value. You will need to the records id to a hidden form field. You will also want to move the code for updating the record outside of the loop. Code for displaying the destination value or edit form if($destination=='') { echo "<form method='post'> <td width='25%'><center> <input type='hidden' name='id' value='$id' /> <input type='text' name='destination_save2' placeholder='Destination Location' /> <input type='submit' name='submit2' value='Update Call' /></center> </td>"; echo "</form>"; } else { echo "<td width='25%'><center>$destination</center></td>"; } Then outside of the loop you'll have the update code if(isset($_POST['submit2'])) { $id = (int) $_POST['id']; $destination_save2 = mysql_real_escape_string($_POST['destination_save2']); $result8=mysql_query("UPDATE uc_calls SET destination='$destination_save2' WHERE id=$id"); if(!$result8) { die('Failed to update call. Please contact your Technical Analyst with this error:<br />' .mysql_error()); } else { header("Location: ?"); } } Link to comment https://forums.phpfreaks.com/topic/283934-updating-too-many-rows/#findComment-1458419 Share on other sites More sharing options...
neverforget98 Posted November 15, 2013 Author Share Posted November 15, 2013 Is this code being ran in a loop? if it is then it'll update every row to the same destination value. You will need to the records id to a hidden form field. You will also want to move the code for updating the record outside of the loop. Code for displaying the destination value or edit form if($destination=='') { echo "<form method='post'> <td width='25%'><center> <input type='hidden' name='id' value='$id' /> <input type='text' name='destination_save2' placeholder='Destination Location' /> <input type='submit' name='submit2' value='Update Call' /></center> </td>"; echo "</form>"; } else { echo "<td width='25%'><center>$destination</center></td>"; } Then outside of the loop you'll have the update code if(isset($_POST['submit2'])) { $id = (int) $_POST['id']; $destination_save2 = mysql_real_escape_string($_POST['destination_save2']); $result8=mysql_query("UPDATE uc_calls SET destination='$destination_save2' WHERE id=$id"); if(!$result8) { die('Failed to update call. Please contact your Technical Analyst with this error:<br />' .mysql_error()); } else { header("Location: ?"); } } Thanks so much Ch0cu3r! Link to comment https://forums.phpfreaks.com/topic/283934-updating-too-many-rows/#findComment-1458475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.