<?php
$conn = mysqli_connect("localhost","root","","furniture");
$vehicle= $_POST['vehicle'];
if($_POST["Submit"] == "Submit")
{
for($i=0; $i<sizeof($vehicle);$i++)
{
$query="INSERT INTO events (status) VALUES ('".$vehicle[$i]."')"; mysqli_query($query) or die (mysqli_error());
}
echo "updated";
}
?>
<html>
<body>
<form action="test.php" method="post">
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
我收到了这个错误:
未定义索引:在C中提交 未定义的索引:C中的车辆
答案 0 :(得分:0)
您错过了mysqli_query
中的参数。把它:mysqli_query($conn,$query)
还要$_POST
var_dump
是否包含数组
答案 1 :(得分:0)
像这样改变你的代码
if(isset($_POST["Submit"]))
{
$vehicle= $_POST['vehicle'];
for($i=0; $i<sizeof($vehicle);$i++)
{
$query="INSERT INTO events (status) VALUES ('".$vehicle[$i]."')"; mysqli_query($query) or die (mysqli_error());
}
echo "updated";
}