I have a problem in inserting value into the database using foreach loop. The values inserted is 0 and only one row will be insert. Below is my input code.
<td bgcolor="#FFFFFF"><input id="id" name="pro_id[]" type="text"></td>
<td bgcolor="#FFFFFF"><input id="name" name="pro_name[]" type="text"></td>
<td bgcolor="#FFFFFF"><input id="quan" name="pro_quan[]" type="text"></td>
Below is my insert code..
if (isset($_POST['Submit'])) {
$username = $_SESSION['admin_id'];
foreach ($_SESSION["products"] as $item)
{
$ids = $item["pro_id"];
$names = $item["pro_name"];
$quans = $item["pro_quan"];
}
$query = "INSERT INTO product(username, pro_id, pro_name, pro_quan) VALUES ('$username', '$ids', '$names', '$quans')";
$result = mysqli_query($con, $query);
if($result)
{
header("Location:delete.php");
}
else
{
mysqli_error($con);
}
}
The values inserted will only be 0. I am not sure what is the error here. Please help me to see what has gone wrong with my code. Thanks for helping