[英]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.