使用PHP预准备语句在数据库中插入跨度值 [英] insert span values in database with PHP Prepared Statements
本文介绍了使用PHP预准备语句在数据库中插入跨度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个联系表格,其中有一些复选框.用户提交表单后,我想在数据库中获取他们的条目.我可以正确执行此操作,但是今天我想更改表单以做出响应.我将简单的复选框更改为跨越标签,但现在无法在数据库中获取值.它没有给我任何错误,但是也没有在数据库中显示任何内容.
I have a contact form where I have some checkboxes. After the user submits the form I want to get their entries in the database. I can do this properly, but today I wanted to change my form to be responsive. I changed my simple checkboxes to span tags, but now I can not get the values in the database. It did not give me any error but also did not show anything in the database.
<html>
<body>
<form action="" method="POST" >
<section>
<div class="wrapper-checkbox">
<div class="checkbox">
<div class="text">
<span name="check1" value="rent">rent</span>
</div>
</div>
<div class="checkbox">
<div class="text">
<span name="check2" value="buy">buy</span>
</div>
</div>
</div>
</section>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js-checkbox/index.js"></script>
</form>
<?php
$check1 = !empty($_POST['check1']) ? $_POST['check1'] : '';
$check2 = !empty($_POST['check2']) ? $_POST['check2'] : '';
if ($stmt = mysqli_prepare($connect, "INSERT INTO $db_table VALUES (?, ?)"))
{
mysqli_stmt_bind_param($stmt, "ss",$check1,$check2);
?>
</body>
</html>
推荐答案
您也可以通过使用表单标签 EX-
You can also done it by using hidden field within a form tag EX-
<input type="hidden" name="check1" value="rent">
并通过
<?php
$check1 = !empty($_POST['check1']) ? $_POST['check1'] : '';
$check2 = !empty($_POST['check2']) ? $_POST['check2'] : '';
?>
这篇关于使用PHP预准备语句在数据库中插入跨度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文