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;