upperbid Posted November 15, 2009 Share Posted November 15, 2009 I have been trying to solve this problem for hours, read all the posts and tried a few I found, but no luck. I have a form preloaded with data from a mysql database. The page pulls about 40 rows from the mysql database at this time. Each row has a checkbox and prefilled input in the fields that can be changed and then updated by checking the checkbox and then hitting the submit button. The problem is that no matter what boxes I check, it updates the wrong rows (unless I select the first row or first and second if updating two rows at once, etc.). It updates the rows starting at the first one displayed on the page, then the second one if I select more than one. Anyhow, I have placed the code into a simple script to simply display the right rows and I can't get it to work. The only thing that is displayed correctly is the ID, but not the sortid or the title. Any help would really be appreciated. Here is the code: while($r=mysql_fetch_array($result)) { $id = $r["id"]; $sortid = $r["sortid"]; $title = $r["title"]; echo "<tr><td>$id<input type=\"checkbox\" name=\"update[]\" value=$id/> <input type=text name=\"sortid[]\" value=$sortid size=1> echo "<input type=text name=\"title[]\" value='$title' size=45></BR></td></tr>"; } ///the form submit button is here, but I left it our to make this code simpler since the form submit is working fine. $checkbox2 = $_POST['update']; $usortid = $_POST['sortid']; $utitle = $_POST["title"]; if (isset($_POST['changes'])) { if (count($checkbox2) > 0) { for ($i=0;$i<count($checkbox2);$i++) { $up_id = $checkbox2[$i]; print $up_id; print $usortid[$i]; print $utitle[$i] . "</br>"; } } } Link to comment https://forums.phpfreaks.com/topic/181608-help-please-with-multiple-rows-mysql-update-from-selected-checkboxes-php/ Share on other sites More sharing options...
alex3 Posted November 15, 2009 Share Posted November 15, 2009 Doesn't mysql_fetch_array() only return a numerical array (eg. $r[1], $r[2], $r[3])? The way you're trying to assign the variables in the loop look more like you should be using mysql_fetch_assoc($result). Link to comment https://forums.phpfreaks.com/topic/181608-help-please-with-multiple-rows-mysql-update-from-selected-checkboxes-php/#findComment-957929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.