0
<?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>
我得到这个错误:PHP的错误,它说未定义的车辆和不确定提交
您的代码我们的代码很容易受到SQL注入式攻击。您应该使用参数化查询和准备语句来帮助防止攻击者通过使用恶意输入值来危害数据库。 http://bobby-tables.com给出了风险的解释,以及如何使用PHP/mysqli安全编写查询的一些示例。切勿将未经协商的数据直接插入到您的SQL中。 – ADyson
[PHP:“注意:未定义的变量”,“注意:未定义的索引”和“注意:未定义的偏移量”的可能重复](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable- notice-undefined-index-and-notice-undef) – iainn
你是否检查过'$ _POST'实际包含的内容? – Carcigenicate