I have a form with an input box (property) and multiple selection menu (categories) and want to allow the user to add property into multiple categories.
My form fields are:
[INDENT]input name="propid"
select name="catid[]"[/INDENT]
My form submits using 'GET' (just so I can see values being passed)
I've tried the following:
$catid = $_GET['catid'];
$propid = $_GET['propid'];
// Explode into an array
$catid = explode(",", $catid);
for($i; $i<=count($catid); $i++){
//insert into database
mysql_select_db($database_conn_new, $conn_new);
$insertSQL="INSERT INTO match_prop_cats (catid, propid) VALUES ('$value[catid]', '$propid')";
echo $sql . '<br>';
mysql_query($insertSQL) or die(mysql_error());
$Result = mysql_query($insertSQL, $conn_new) or die(mysql_error());
The result for the above was that the value entered for $catid was 0. It did however insert the $propid multiple times okay
And when I tried this way:
$catid = $_GET['catid'];
$propid = $_GET['propid'];
foreach ($_GET['catid'] as $key => $value)
mysql_select_db($database_conn_new, $conn_new);
$insertSQL="INSERT INTO match_prop_cats (catid, propid) VALUES ('$value[catid]', '$propid')";
echo $sql . '<br>';
mysql_query($insertSQL) or die(mysql_error());
$Result = mysql_query($insertSQL, $conn_new) or die(mysql_error());
... again $propid was okay but only the first value for $catid was inserted multiple times!
What in the world am I not seeing here? :eek: