I have a form with multiple fields like that:
<input type="text" name="name[]" value="">
<input type="text" name="name[]" value="">
<input type="text" name="name[]" value="">
I am trying to insert submit that form and those values to an array in database:
<?php
$i = 0;
foreach ($_POST as $val) {
$name = $_POST['name'][$i];
mysqli_query("INSERT INTO main (name) VALUES ('$name')");
$i++;
}
?>
This is giving me error "mysqli_query() expects at least 2 parameters, 1 given"
I also tried replacing the query with:
mysqli_query($connect, "UPDATE main
SET name='$name'
WHERE id=2");
But I think this is not actually posting 3 values of name to an array. Instead its posting only one.
I tried to use multiple codes that I found on this website but I still can't figure it out!
$connectto your first call tomysqli_querybut why did you add theWHEREcondition to your second one?