i cant seem checkbox update checked boxes. right when check box , click submit, marks final row value of 1 (even if row isn't checked). missing here in order post same page , update boxes checked?
while($row = mysql_fetch_array( $result )) { $addr = $row['address']; $info = $row['info']; $date = $row['date']; $status = $row['status']; $id = $row['id']; ?> <tr> <td><?php echo $id; ?></td> <td><?php echo $addr; ?></td> <td><?php echo $info; ?></td> <td><?php echo $date; ?></td> <td><?php echo $status; ?></td> <td><input type="checkbox" name="handled" value="1"><br></td> </tr> <?php } ?> </table> <?php if (isset($_post['checked'])) { echo "posted!"; $sql2 = "update requests set status = 1 id = '".$id."'"; mysql_query($sql2) or die(mysql_error()); } ?> <br> <form action="" method="post"> <input name="checked" type="submit"/>
your code vulnerable sql injection. use either mysqli or pdo
update specific part of code following in php , put checkbox inside form.
<?php if (isset($_post)) { echo "posted!"; //uncomment print_r debugging //print_r($_post); if(isset($_post['handled'])=='on') { echo "checkbox checked ".$id." update status id"; $sql2 = "update requests set status = 1 id = '".$id."'"; //do querying here } else { echo "checkbox not checked ".$id; } } ?>
and form
<form action="" method="post"> <!-- put checkbox inside form --> <input type="checkbox" name="handled"/> <input name="checked" type="submit"/>
[edit]
one thing have know checkbox unchecked checkboxes not posted. lets if have textbox no value, on submit null textbox posted, in case of checkboxes if checkbox not marked post ignores/avoid null value, in case treated non existing element. nothing posted, not null value. overcome use hidden field checkbox submit value automatically checkbox value in manupulated javascript onchange of checkbox checked or not.
Comments
Post a Comment