Forum Moderators: coopster
I've got a checkbox form where users can select multiple records to be inserted into a table.
My insert query keeps throwing an error though, and I've gone positively cross-eyed trying to figure out why. Can you help?
Error message:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '6','10624'),('6','10623')')' at line 2
my processing page code is as follows:
$array = $_POST['array'];
$insertvalues=array();
foreach($array as $key => $value) {
print "$key: $value[p] $value[b]<br>";
if(!$value[b]){
}
else
{
$insertvalues[]="('{$value['p']}','{$value['b']}')";
}
}
if(count($insertvalues >0)){
$query = mysql_query("INSERT INTO projectblockyear (projectid, blkyr)
VALUES('".implode(",",$insertvalues)."')")
or die (mysql_error());
--------------------------------------------------
print_r($insertvalues) produces:
Array ( [0] => ('6','10624') [1] => ('6','10623') )
Query now reads:
$query = mysql_query("INSERT INTO projectblockyear (projectid, blkyr) VALUES(".implode(",",$insertvalues).")")
or die (mysql_error());
... but produces a new error:
Operand should contain 1 column(s)
What I've found indicates that this is a mismatch between the number of table fields I've specified and the number of insert values? Any suggestions?