I'm trying to figure out why this MYSQL INSERT inside the foreach doesn't insert anything into mysql database!
// Parse the form data and add inventory item to the system
if (isset($_POST['g_name'])) {
$g_name =$_POST['g_name'];
$numbers = $_POST['numbers'];
$comma_separated = explode(", ", $numbers);
foreach($comma_separated as $seperate){
$sql .="INSERT INTO groups(`g_name`, `numbers`) VALUES ('$g_name','$seperate')";
}
$query = mysqli_query($db_conx, $sql);
header("location: groups.php");
exit();
}
if I change the $sql .=
to $sql =
it inserts only one value in the MYSQL database.
the value of $numbers
is like this: 1, 2, 3, 4, 5
could someone please advise on this issue?
any help would be appreciated.