Jump to content

Help Please with Multiple rows MYSQL update from selected checkboxes php


upperbid

Recommended Posts

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

}
   }
}

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.