I have a checkbox naming problem!

What I am trying to do is to insert in to mysql a $varible only where a checkbox is is check in the form.

I have a while statement that show all the items in a members cart and i'm to make it where if they want an item shipped they select a checkbox for that Item and it will update a field the mysql table.

my issue is that the number checkboxes varies with the number of items and the chosing the name of the field for mysql to identify which item to update.

Here is what I have:

$i=1;
$resulta = mysql_query("SELECT * FROM testtitles WHERE orderid='$itmx' ",$db);
while($myrowx= @mysql_fetch_array($resulta)){
$item = $myrowx["item"];

$io+=$i;

echo "<br/><table width=600 border=0><tr><td align=left>
<b>Item No: $xxitemnumberx</b>
<br/>
$xxtitlex
</td></tr><tr><td>
<table border=0 width=\"600\">
<tr>
<td width=75 class=style5><u>Item</u></td>
<td align=center class=style5>Pack It!</td>
</tr>
<tr>
<td width=75 class=style3>$item</td>
<td align=center><input type=\"checkbox\" name=\"sel$io\" value=\"Packed\"><input type=hidden name=selitmx value=$xxitemnumberx>

</td></tr></table>";
if (submit){
$queryp = "update testtitles SET ship_status='Shipped', ship_date='$datex' WHERE itemnumber = '$selitmx' AND sel$io = 'Packed' ";
$resultp = mysql_query($queryp);

}}

I'm sure this has been done before but I can't seem to any examples quite like it. Any Ideas?

    you need to set your checkboxes as arrays.

    echo "<input type=\"checkbox\" name\"fieldname[".$row["id"]."]\" value=\"1\">\n";

    in your update or query:

    if (is_array($_POST["fieldname"])) {
        foreach ($_POST["fieldname"] as $key => $value) {
            $sql = "UPDATE table SET fieldname = '$value' WHERE id = $key";
        }
    }

      Thanks for your reply.

      I can't seem to get it to fly.

      It is probably just my inexperience

      I hope you can help me further.

      This is what i have now:
      $_POST['ship_status'];

      if($viewx){

      $resultas = mysql_query("SELECT * FROM testinfo WHERE orderid='$itmx' ",$db);
      $urows = mysql_fetch_array($resultas);

      echo"<form name=orderx method=POST action=ship.php>

      $resulta = mysql_query("SELECT * FROM testtitles WHERE orderid='$itmx' ",$db);
      while($myrowx= @mysql_fetch_array($resulta)){

      <td align=center><input type=\"checkbox\" name=\"ship_status[".$myrow2x["ship_status"]."]\" value=\"1\">

      </td></tr></table>";

      }
      if (sub){
      if (is_array($POST["ship_status"])) {
      foreach ($
      POST["ship_status"] as $key => $value) {
      $sql = "UPDATE table SET ship_status = '$value' WHERE ship_status = $key";
      }
      }

      }

      echo "<table width=\"600\" border=\"0\"><tr><td><br/><input type=\"submit\" name=\"sub\" value=\" Ship Items! \">
      </form></td></tr></table>";

        Write a Reply...