Forum Moderators: coopster

Message Too Old, No Replies

Update table: multiple checked checkbox

how to update mysql from a multiple checked checkbox

         

winG

5:36 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



Hi there.
I just started to learn PHP.erm..n facing some problem here.:(
I have 5 records displayed.I need to use checkbox to update my 5 records after clicking submit button.However,i only manage to update the last checked checkbox records instead of all 5 records from the checked checkbox.This is the code:
the checkbox is generated while there's still records.

while($query_data = mysql_fetch_array($result))
{ $vacc_id = $query_data["vacc_id"];
:
<td><input type="checkbox" name="approve[]" id="chkapprove" value="<?php echo"$vacc_id";?>"></td>

code after button submit,

$fields = $_POST['approve'];
if (count($fields) > 0)
{
$content = $content . count($fields);
for ($i=0;$i<count($fields);$i++)
{
$content = $fields[$i];}
}
}
$query = "UPDATE $tbl_status SET visa_status = 'Successful' where vacc_id = '$content'";

what do i need to change?

dreamcatcher

7:53 pm on Mar 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



winG, welcome to Webmaster World. :)

Try using a foreach loop when you process:

foreach ($_POST['approve'] as $entry)
{
$query = "UPDATE $tbl_status SET visa_status = 'Successful' where vacc_id = '$entry'";
}

Hope that helps.

dc

winG

5:19 pm on Mar 16, 2005 (gmt 0)

10+ Year Member



Thanks! dreamcatcher. :)
just a simple foreach loop and tada~ problem solved.
again,thank you very much!

dreamcatcher

7:17 pm on Mar 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You`re welcome. :)