简体   繁体   English

如何使用PHP从复选框中获取值?

[英]How do I get a value from a check box with PHP?

I have a form where there is a check box, on selecting this box values from different page gets loaded through ajax, after loading these values user can select them and then submit it and save it in database. 我有一个表格,其中有一个复选框,选择此复选框后,来自不同页面的值将通过ajax加载,加载这些值后,用户可以选择它们,然后提交并将其保存在数据库中。

Values are getting loaded properly, however when I submit the form, the values are not getting carried to the backend. 值已正确加载,但是当我提交表单时,值没有被携带到后端。

<!doctype html>
<head>
    <script>
    $(document).ready(function () {
        $('#drive').change(function () {
            if ($(this).is(':checked')) {
                var catid = $('#drive').val();
                console.log($('#drive'))
                if (catid != 0)

                {
                    LodingAnimate();
                    $.ajax({
                        type: 'post',
                        url: 'c_datetime.php',
                        data: {
                            id: catid
                        },
                        cache: false,
                        success: function (returndata) {
                            $('#datetime').html(returndata);
                            console.log(returndata)
                        }
                    });

                    function LodingAnimate() {
                        $("#datetime").html('<img src="img/ajax-loader.gif" height="40" width="40"/>');
                    }
                }
            }else{
                $("#datetime").hide();
            }
        })
    })
    </script>
</head>
<body>  
    <?php
        if($_POST['save'])
            {
                $datee = mysqli_real_escape_string($con, $_POST['datee']);
                $timee = mysqli_real_escape_string($con, $_POST['timee']);
                echo $datee;
                echo $timee;
            }
    ?>
    <form class="form-horizontal"  enctype="multipart/form-data" role="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
        <input type="checkbox" name ="chk" id="drive" value="Drive" style="margin-left: -20px;" >Drive
        <div id="datetime"> </div>
        <button class="btn btn-default btn-border" style="color:white; border-radius: 25px;" type="submit" value="submit" name="save">PROCEED TO POSTING</button>
    </form>
</body>
</html>

c_datetime.php c_datetime.php

<input type='text' class="form-control" name="datee" />
<input type='text' name="timee" class="form-control" />

Can anyone please tell how to resolve this issue? 谁能告诉我如何解决此问题?

You have error in this part. 您在这部分中有错误。 To see errors error_reporting(E_ALL); 查看错误error_reporting(E_ALL);

<?php
    if(isset($_POST['save']))// added isset.
        {
            $datee = mysqli_real_escape_string($con, $_POST['datee']);
            $timee = mysqli_real_escape_string($con, $_POST['timee']);
            echo $datee;
            echo $timee;
        }
?>

What is $con ?? 什么是$con If its connection object, you have missed include() in your code. 如果它是连接对象,则您在代码中错过了include()

暂无
暂无

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

相关问题 如何获取切换复选框的值 - how can I get the value of toggle check box 如何从复选框列表中获取复选框检查值并在选中复选框时调用Ajax函数? - How to Get the check box checked value from list of checkboxes and call an Ajax function when check box is checked? 如果用户未选中复选框或单选按钮,如何为复选框或单选按钮设置一些默认值 - how do I set some default value for a check box or a radio button if user do not check the check box or select a button 如何从iframe内部的选择框中获取所选值,并将其显示在外部? - How do I get the selected value from a select box, from inside an Iframe, and display it on the outside? 如何从传递到其同级组件的下拉框中获取ref值? - How do I get the ref value from a drop down box passed to its sibling component? 如何从下拉列表和显示的输入框中获取增加的价值? - How do I get the added value from a drop down list and an input box to show? 如何从选择框中获取选定的值,并将其用于HTML链接? - How do I get the selected value from a select box, and use it in a HTML link? 我如何从 textarea 获取价值并检查它? - How I get value from textarea and check it? 我如何获取按钮值以显示在文本框中 - how do i get the button value to display in the text box 如何获取输入字段的值并将其显示在对话框中? - How do I get the value of input fields and display it on the dialog box?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM