im trying to update checkbox value into database. i already write some code and it worked updating the database..however for some reason i got undefined index in my combobox variable..here is my code..
code to display existing data into checkbox
<tr>
<td><label for="cbPin">Pin this post</label></td>
<td><input type="checkbox" name="cbPin" class="checkbox checkbox-warning" id="cbPin" <?php
if ($pin == 0) {
?> value="0" <?php
} else {
?> checked value="1" <?php
} ?>
/></td>
</tr>
this one is variable to render the form
$pin = $row[9];
and this one if button submit clicked
$pin = ($_POST['cbPin']);
if ($pin == '') {
$pinpost = 0;
} else {
$pinpost = 1;
}
and this is my query
if ($stmt = $mysqli->prepare("UPDATE tblanouncement SET title = ?, message = ?, pinpost = ? WHERE anouncementId=?"))
{
$stmt->bind_param("ssii",$title, $message, $pinpost, $id);
$stmt->execute();
$stmt->close();
A checked checkbox sends its name and value.
A non-checked checkbox is not a successful control and won't be submitted at all.
If you aren't dealing with multiple checkboxes of the same name, use isset
to see if the data exists or not. Don't assume you will have a value for it in the POST data array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.