problems with inserting multiple rows with an array
Posted: Fri Dec 05, 2003 9:24 pm
This was working, but I'm not sure what happened as it is no longer working.
It should build an array from a check box form element, then insert it into a mysql database table. It should insert 1 column that is a consistant variable, and a second column should contain a unique variable that is in the array.
Currently it is only inserting the last item in the array and ignoring the first two.
my insert statement
my form code
the selectedfile[] array should contain a variety of variables.
the selectedpageid would be a constant, non changing, variable once the page is loaded, we'll say it = "1" for now, though it could also be 2, 3, or 4.
Any ideas on how I can get it to insert multiple rows into the table?
Thanks!
It should build an array from a check box form element, then insert it into a mysql database table. It should insert 1 column that is a consistant variable, and a second column should contain a unique variable that is in the array.
Currently it is only inserting the last item in the array and ignoring the first two.
my insert statement
Code: Select all
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "addfiles")) {
foreach ($selectedfile as $tempvalue) {
$insertSQL = sprintf("INSERT INTO filetopage (page, file) VALUES ($selectedpageid, $tempvalue)");
}
mysql_select_db($database_cms, $cms);
$Result1 = mysql_query($insertSQL, $cms) or die(mysql_error());
}my form code
Code: Select all
<input name='selectedfile[]' type='checkbox' value='" . $test_value . "'>";the selectedfile[] array should contain a variety of variables.
the selectedpageid would be a constant, non changing, variable once the page is loaded, we'll say it = "1" for now, though it could also be 2, 3, or 4.
Any ideas on how I can get it to insert multiple rows into the table?
Thanks!