I have the following checkbox items and I want to insert them in the database.
<form action="test.php" method="post">
<input type="checkbox" name="check_list[]" value="rice:10">
<input type="checkbox" name="check_list[]" value="milk:8">
<input type="checkbox" name="check_list[]" value="orange:4">
<input type="submit" />
</form>
The following is the php code:
if(!empty($_POST['check_list'])) {
foreach($_POST['check_list'] as $check) {
$mealA = explode(":",$check);
$meal = $mealA[0];
$sql1 = "INSERT INTO Order (User, Meal, Total) VALUES ('$name' , '$meal', '$total')";
if (mysqli_query($mysqli,$sql1)) {
echo "You order has been recieved";
} else {
echo "Error: " . $sql1;
}
}
}
Note that the value of each checkbox means item name:price.
The problem is that I got error "Error: " . $sql1;
$mysqlivalue coming from ?mysqli_errorto your code: php.net/manual/en/mysqli.error.php"Error: " . $sql1to"Error:" . mysqli_error($mysqli)so you can have a better understanding of why it fails.Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Order (User, Meal, Total) VALUES ('bero' , 'margherita', )' at line 1Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Order (User, Meal, Total) VALUES ('bero' , 'sicilian', )' at line 1