简体   繁体   English

更新复选框值到数据库

[英]updating checkbox value to database

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. 如果您不处理多个同名的复选框,请使用isset查看数据是否存在。 Don't assume you will have a value for it in the POST data array. 不要假设您在POST数据数组中将有一个值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM