-1

我正在编写巨大的 html 表单,它通过 php 将数据存储在数据库中,但我的复选框代码不起作用

////复选框代码////

<li>Mother </li><table><tr><td><input type="checkbox" name="mdeceased"               value="deceased">deceased</td>
<td><input type="checkbox" name="malive" value="alive">alive</td></tr>
<tr><td><input type="checkbox" name="mretired" value="retired">retired</td>
<td><input type="checkbox" name="minservice" value="inservice">in service</td>
<td><input type="checkbox" name="mbusiness" value="business">business</td></tr>

///用于制作变量然后在查询中使用的复选框的php代码 ///

$mysql = new mysqli('localhost','root','ramsha','scholarships_system') or die ('you\'re     dead');
if(!empty($_POST['submit'])) {
$mdeceased =$_POST['mdeceased'];
$malive = $_POST['malive'];
$mretired = $_POST['mretired'];
$minservice = $_POST['minservice'];
$mbusiness = $_POST['mbusiness'];


$query = "INSERT INTO student _details      VALUES('$mdeceased','$malive','$mretired','$minservice','$mbusiness')";

if($updateDb = $mysql->query($query) or die($mysql->error)) {
        echo "Congrats!";
    }

///错误来了 /// 注意:未定义的索引:第 91 行的 C:\wamp\www\student formfilling\htmlform.php 中的 mdeased

只有 $alive 接受做什么

4

1 回答 1

0

我结束了打开的<input>标签,只是做了一个空检查。它开始工作了。

问题是您试图保存一个从未设置/初始化的变量。

<?php
$mysql = new mysqli('localhost','root','Subha#143','test') or die ('you\'re     dead');
if(isset($_POST['submit'])) {
$mdeceased =isset($_POST['mdeceased'])?$_POST['mdeceased']:null;
$malive = isset($_POST['malive'])?$_POST['malive']:null;
$mretired = isset($_POST['mretired'])?$_POST['mretired']:null;
$minservice = isset($_POST['minservice'])?$_POST['minservice']:null;
$mbusiness = isset($_POST['mbusiness'])?$_POST['mbusiness']:null;

$query = "INSERT INTO student_details VALUES('$mdeceased','$malive','$mretired','$minservice','$mbusiness')";

if($updateDb = $mysql->query($query) or die($mysql->error)) {
        echo "Congrats!";
    }
}else{echo("post is not set");}
?>
于 2013-09-03T17:43:13.123 回答