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

时间:2022-01-22 08:57:37

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

<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?

谁能告诉我们如何解决这个问题?

1 个解决方案

#1


0  

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?? If its connection object, you have missed include() in your code.

什么是$ con ??如果是它的连接对象,则在代码中错过了include()。

#1


0  

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?? If its connection object, you have missed include() in your code.

什么是$ con ??如果是它的连接对象,则在代码中错过了include()。