whitemoss Posted February 28, 2007 Share Posted February 28, 2007 Hi all, I would like to write a code to immediately update the database, once a checkbox has been checked or unchecked. I already wrote a code for updating purposes but it didnt work as expected. It only brings the same value or id of checkbox even though I select other checkbox or select more than 1 checkbox. below is the code: <? $i = 1; $j = 1; while ($row = mysql_fetch_array($result)) { //while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $bil = $i; //+ ($PageaNo-1)*$PageSize; $id = $row['RecordID']; $date = $row['Date']; $event = $row['Event']; ?> <tr bgcolor="#CCCCCC"> <td align="center" width="50"><?php echo $bil; ?></td> <td align="center" width="50"><? echo "<input name='checkbox[$id]' id='$id' type='checkbox' value='$id'>"?></td> <td align="center" width="250"><?php echo $event; ?></td> <?php $i++; $j++; } ?> .... .... some codes here .... <td align="center"> <form name="form4" method="post" action="newPublicHoliday.php"> <input name="Add" type="submit" id="Add" value="Add Event"> </form> </td> <? if ($_POST['Submit']) { //$checkbox = $_POST["checkbox"]; $checkbox = $_POST['checkbox']; $id = $_POST['id']; echo $checkbox; echo $id; //foreach ($checkbox as $key => $value ) //{ //echo $id[$key]." ".$value; $update = "Update Holiday set Status=1 where RecordID=$id"; mysql_query($update); echo $update; //} } ?> Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted February 28, 2007 Share Posted February 28, 2007 see this sample: if(isset($_POST['leaves'])) { foreach ($_POST['leaves'] as $value) { $sql="update leave_apps set archive=1 where leave_apps.id='$value'"; $c_leaves->query($sql); } } while ($row=$c_leaves->fetch_array($res)) { echo "<tr class='alt1'>"; echo "<td class='data' width=1%><input type=checkbox name='leaves[]' value='$row[leave_id]' /></td>"; echo "</tr"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.