I have four arrays:
$qtys = $_POST['qty'];
$colours = $_POST['colour'];
$sizes = $_POST['size'];
$names = $_POST['name'];
I want these to go into a mysql table like so:
qty | colour | size | name
-------------------------------------------
$qtys[0] | $colour[0] | $size[0] | $name[0]
$qtys[1] | $colour[1] | $size[1] | $name[1]
I’ve tried various things, including this:
foreach($qtys as $value) {
$i = 0;
mysql_query("INSERT INTO table (qty,colour,size,name) VALUES ('$qtys[$i]','$colours[$i]','$sizes[$i]','$names[$i]')");
$i++;
}
…but to no avail. Can anyone suggest a different INSERT statement that will get the data in the table? Do I need to iterate in the loop? I’m sure $qtys as $value is incorrect but have tried so many things with no luck.
Simply use for loop will be ok, AND REMEMBER ESCAPE USER INPUT.