php错误,它表示未定义的车辆和未定义的提交

时间:2017-09-25 16:05:24

标签: php

<?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中的车辆

2 个答案:

答案 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";
}