繁体   English   中英

在php中发送复选框值

[英]send checkbox value in php

有谁知道如何在每次我勾选表单中的复选框时在 php 中编码? 当我勾选复选框时,该值假设实际插入到我的数据库中的 id 列中,并且每次我勾选并提交表单时它都会自动增加。

你需要使用ajax。 以下是代码片段。

$('input:radio[name="tickExam"]').click(function() {
if(this.checked){
        $.ajax({
            type: "POST",
            url: 'increase.php',
            data: {id:$(this).val()},
            success: function(data) {
                alert('Increased.....');
            },
             error: function() {
                alert('Sorry! there was an issue');
            }
        });

        }
  });

在increase.php 中编写代码以增加表中的值。

好的,所以你有这个:

<form ...>
    <table>
        <tr>
            <td>
            </td>
            //...
            <td>
                <input type='checkbox' value='YOUR_ID' name='checkboxarray[]'/>
            </td>
        </tr>
    </table>
    <input name='submit' type='submit' ...>
</form>

您希望在提交时,相应的 ID 数据库记录“计数器字段”增加 1 'IF THE BOX IS CHECKED'

然后,这样做:

//if you posted : 
if(isset($_POST['submit'])){
    //here you have to handle your data
    //your checkbox array is not empty IF there is something checked, so : 
    if(is_array($_POST['checkboxarray'])){
        foreach($_POST['checkboxarray'] as $value){
            //HERE YOUR $VALUE IS THE ID OF THE DB RECORD (if you dit id the way I explain it over), so do your database stuff here, just increase your field WHERE id = $value !
        }
    }else{
        //no checkboxes checked
    }
}else{
    //nothing posted, just display your form
}

那是你需要的吗?

有谁知道如何在每次我勾选表单中的复选框时在 php 中编码? 当我勾选复选框时,假设该值实际上插入到我的数据库中的 id 列中,并且每次我勾选并提交表单时它都会自动增加。

当您说“每次我勾选并提交表单”时考虑您的帖子,那么在您的情况下无需使用 javascript 或 ajax

暂无
暂无

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

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