我有这样的php代码:
<?php
if(isset($_POST['submit']))
{
if(!empty($_POST['vehicles']))
{
$vehicles=$_POST['vehicles'];
$hostname='localhost';
$username='root';
$password='root';
$dbname='pet';
$connect=mysqli_connect($hostname,$username,$password,$dbname) or die("can't connect to server");
$query="UPDATE information SET transportation='$vehicles'";
$query=mysqli_query($connect,$query) or die("can't execute query");
echo "inserted";
}
else
{
echo "error";
}
}
else
{
echo "choose your vehicle";
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Select transportation you have</title>
</head>
<body><h2>Select transportation you have</h2>
<form action="#" method="POST">
<input type="checkbox" name="vehicles" value="bike"/>I have bike<br/>
<input type="checkbox" name="vehicles" value="car"/>I have car<br/>
<input type="checkbox" name="vehicles" value="motor"/>I have motor<br/>
<input type="submit" name="submit" value="submit"/>
</form>
</html>
当我选择多个选项时,我的数据库中只有一个值。例如,我选择自行车和电机。数据库中只有电机