I'm sort of posting this here just to see what it looks like in the PHP tags. I have built 3 different sets of pages (similar structure, but collecting different kinds of data) that work just fine.
But This section consistently gives me an error and does not complete the INSERT operation. Been puzzling over this all day...
Like I said, I'm just posting this in the PHP tags to see what it looks like, but if anyone who looks at it sees anything obvious, please chime in!
$Link = mysql_connect($Host,$User,$Password);
mysql_select_db($DBName);
//don't remove or add any columns
$sql = 'INSERT INTO '.$TableName.' (SCHOOLID, GRADE, ROOM, MPSID, LAST, FIRST, TESTDATE, TESTPHASE, DIBELS_IS_RAW, DIBELS_IS_TIME, DIBELS_IS_FINAL, DIBELS_WORD_USE, DIBELS_LETTER_NAMING, DIBELS_PHONEME_SEG, DIBELS_NW, DIBELS_RETELL, DORF1WR, DORF1ERR, DORF1WRC, DORF2WR, DORF2ERR, DORF2WRC, DORF3WR, DORF3ERR, DORF3WRC, DORF_MWR, DORF_MERR, DORF_MWRC, DATANOTE, LANG, PRIDDIBIS, PRIDDIBWU, PRIDDIBLN, PRIDDIBPS, PRIDDIBNW, PRIDDIBSR, PRIDDORF1, PRIDDORF2, PRIDDORF3, SUBMITTER, DATASUBMIT, PROBLEV, DATAPOINTID) VALUES ';
// need extra counter as we might not enter all lines from the arrays
$j = 0;
for ($i=0; $i<count($SCHOOLID); $i++) {
//the next line checks to see if there are scores in ALL 3 DORFwr cells
if ($DORF1WR[$i] && $DORF2WR[$i] && $DORF3WR[$i]) {
if ($j == 0) {
$sql .= "('$SCHOOLID[$i]', '$GRADE[$i]', '$ROOM[$i]', '$MPSID[$i]', '$LAST[$i]', '$FIRST[$i]', '$TESTDATE[$i]', '$TESTPHASE[$i]', '$DIBELS_IS_RAW[$i]', '$DIBELS_IS_TIME[$i]','".(($DIBELS_IS_RAW[$i]*60)/$DIBELS_IS_TIME[$i])."', '$DIBELS_WORD_USE[$i]', '$DIBELS_LETTER_NAMING[$i]', '$DIBELS_PHONEME_SEG[$i]', '$DIBELS_NW[$i]', '$DIBELS_RETELL[$i]', '$DORF1WR[$i]', '$DORF1ERR[$i]', ".($DORF1WR[$i]-$DORF1ERR[$i]).", '$DORF2WR[$i]', '$DORF2ERR[$i]', ".($DORF2WR[$i]-$DORF2ERR[$i]).", '$DORF3WR[$i]', '$DORF3ERR[$i]', ".($DORF3WR[$i]-$DORF3ERR[$i]).", '$MWR[$i]', '$MERR[$i]', '$MWRC[$i]', '$DATANOTE[$i]', '$LANG[$i]', '$PRIDDIBIS[$i]', '$PRIDDIBWU[$i]', '$PRIDDIBLN[$i]', '$PRIDDIBPS[$i]', '$PRIDDIBNW[$i]', '$PRIDDIBSR[$i]', '$PRIDDORF1[$i]', '$PRIDDORF2[$i]', '$PRIDDORF3[$i]', '$SUBMITTER[$i]', Now(), '', '')";
}
else {
$sql .= ",('$SCHOOLID[$i]', '$GRADE[$i]', '$ROOM[$i]', '$MPSID[$i]', '$LAST[$i]', '$FIRST[$i]', '$TESTDATE[$i]', '$TESTPHASE[$i]', '$DIBELS_IS_RAW[$i]', '$DIBELS_IS_TIME[$i]','".(($DIBELS_IS_RAW[$i]*60)/$DIBELS_IS_TIME[$i])."', '$DIBELS_WORD_USE[$i]', '$DIBELS_LETTER_NAMING[$i]', '$DIBELS_PHONEME_SEG[$i]', '$DIBELS_NW[$i]', '$DIBELS_RETELL[$i]', '$DORF1WR[$i]', '$DORF1ERR[$i]', ".($DORF1WR[$i]-$DORF1ERR[$i]).", '$DORF2WR[$i]', '$DORF2ERR[$i]', ".($DORF2WR[$i]-$DORF2ERR[$i]).", '$DORF3WR[$i]', '$DORF3ERR[$i]', ".($DORF3WR[$i]-$DORF3ERR[$i]).", '$MWR[$i]', '$MERR[$i]', '$MWRC[$i]', '$DATANOTE[$i]', '$LANG[$i]', '$PRIDDIBIS[$i]', '$PRIDDIBWU[$i]', '$PRIDDIBLN[$i]', '$PRIDDIBPS[$i]', '$PRIDDIBNW[$i]', '$PRIDDIBSR[$i]', '$PRIDDORF1[$i]', '$PRIDDORF2[$i]', '$PRIDDORF3[$i]', '$SUBMITTER[$i]', Now(), '', '')";
}
// increment counter
$j++;
} // end if for checking user input
} // end for loop
// then do insert
if (mysql_query($sql,$Link))
print ("Got it. Thanks for the data!<BR>\n");
else
print ("Sorry. Didn't get the data. Joe messed up the script!<BR>\nMySQL error: " . mysql_error() . "<BR>\nQuery: $sql<BR>\n");
mysql_close($Link);
The error I get is:
MySQL error: You have an error in your SQL syntax near '' at line 1
Query: INSERT INTO DATADIBELS (SCHOOLID, GRADE, ROOM, MPSID, LAST, FIRST, TESTDATE, TESTPHASE, DIBELS_IS_RAW, DIBELS_IS_TIME, DIBELS_IS_FINAL, DIBELS_WORD_USE, DIBELS_LETTER_NAMING, DIBELS_PHONEME_SEG, DIBELS_NW, DIBELS_RETELL, DORF1WR, DORF1ERR, DORF1WRC, DORF2WR, DORF2ERR, DORF2WRC, DORF3WR, DORF3ERR, DORF3WRC, DORF_MWR, DORF_MERR, DORF_MWRC, DATANOTE, LANG, PRIDDIBIS, PRIDDIBWU, PRIDDIBLN, PRIDDIBPS, PRIDDIBNW, PRIDDIBSR, PRIDDORF1, PRIDDORF2, PRIDDORF3, SUBMITTER, DATASUBMIT, PROBLEV, DATAPOINTID) VALUES
And that's it. Like it is not processing anything past the insert statement. No subsequent value strings appear in the error.