gpt4 book ai didi

php - 如何通过php将复选框项目存储在数据库中

转载 作者:行者123 更新时间:2023-11-29 13:37:05 26 4
gpt4 key购买 nike

我正在编写巨大的 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!";
}

///错误即将到来///注意:未定义索引:mdeceased位于C:\wamp\www\student formfilling\htmlform.php第91行

只有 $alive 接受该怎么办

最佳答案

我结束了开放<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");}
?>

关于php - 如何通过php将复选框项目存储在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18597112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com