trying to insert multiple values in my mySQL database this is what I’ve got so far.
if (in_array(",", $_POST['categories'])) { /* Other was selected */}
$cat = implode(" ,", $_POST['categories']);
if (in_array(",", $_POST['subcat'])) { /* Other was selected */}
$sub = implode(" ,", $_POST['subcat']);
if (in_array(",", $_POST['type'])) { /* Other was selected */}
$type = implode(" ,", $_POST['type']);
if (in_array(",", $_POST['payment'])) { /* Other was selected */}
$payment = implode(" ,", $_POST['payment']);
$sql = "INSERT INTO tbl_locations SET
name='".$_POST['name']."',
alias='".$_POST['alias']."',
category_id='$cat',
subcategory_id='$sub',
tourism_type_id='$type',
lgu_id='$payment',
latitude='".$_POST['latbox']."',
longitude='".$_POST['lngbox']."'
";
$qry= mysql_query($sql) or die (mysql_error());
if ($qry)
{
header("location:addsuccess.php");
exit();
}
As you can see there are not just 1 multiple entries but 4. . . would appreciate on how to proceed on this. .. also my form all has name=name[] so no problems on the form. It just inserts single values into my db rather than multiple.
The problem with your application is your database design. If you can have multiple categories, types, payments, etc. then you need a relational model that can handle this. One way of doing this would be to have one table that handles your requests, then child tables for categories, types, payments, etc of each request.
And so on.