我在尝试提交此表单时遇到了一个问题,其中隐藏了用文本标记的复选框。我使用 CSS 而不是 JavaScript 来显示/隐藏内容,我需要这样做。
<form method="post" action="" class="table_info3_form1">
<h3>Materialy</h3>
Materialy: <input type="text" name="materialy">
<label class="collapse" for="ajfarebne"><b>Aj farebne materialy ?: (click)</b></label>
<input id="ajfarebne" type="checkbox" name="ajfarebne">
<div>Menia sa farby pravidelne, alebo len obcas ?<input type="text" name="meniasa"/></div><br>
PC a PMMA: <input type="text" name="pcapmma">
<br>Iny transparentny material: <input type="text" name="inytransparentny"><br>
Frekvencia cistenia strojov: <input type="text" name="frekvencia"><br>
Najvacsi problem pri cisteni: <input type="text" name="najvacsiproblem"><br>
</form>
使用这个 css(我添加这个,因为它是显示/隐藏工作所必需的):
.collapse{
display:block;
}
.collapse + input{
display:none;
}
.collapse + input + *{
display:none;
}
.collapse+ input:checked + *{
display:block;
}
php 代码是这样的(我把数据存储在这样的变量中):
if(isset($_POST['submit']))
{
$materialy=mysql_real_escape_string($_POST['materialy']);
$meniasa=mysql_real_escape_string($_POST['meniasa']);
... more variables
if(isset($_GET['qs']))
{
$id = $_GET['qs'];
if (isset($_POST['ajfarebne'])){ $ajfarebne=1; else $ajfarebne=0; //defining my checkbox variable value
然后我将值插入数据库:
$query1=mysql_query("INSERT INTO properties3 VALUES('', '$materialy', '$ajfarebne', '$meniasa'... more variables
然后我重定向:
if($query1)
{
$query1=mysql_query("select idfirma3 from properties3 where idfirma3='$id'");
$query4=mysql_fetch_array($query1);
header("location:../firma/firma-properties.php?id=".$query4['idfirma3']."");
}
问题:
此表单不会执行任何操作。这意味着它不会将数据存储到我的表中,最终也不会重定向到任何位置。
怎么了?
最佳答案
尝试 mysqli_query
并确保您已连接到数据库,然后执行此操作:
if (mysqli_query($con, "INSERT... ")){
... //code here
}
祝你好运!
关于javascript - 带有复选框的PHP表单不插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24766950/