Okay, here's yet another poser from me:
With all the help I've gotten here, I've learned how to create a multi-line, multi-field form that submits each line as a record into a MySQL database table. I'm really happy about this and grateful.
Now I'd like to figure out how to keep empty rows (or rows where particular fields were left blank) from being submitted when the user submits the form.
I thought I might be able put a WHERE clause at the end of my INSERT INTO statement...but it does not work. Here is what I tried:
$Link = mysql_connect($Host, $User, $Password);
mysql_select_db($DBName);
//THIS IS WHERE I WAS STUCK! Contribution from nnichols on phpbuilder.com got me through it. Thanks!
//don't remove or add any columns
$sql = 'INSERT INTO '.$TableName .'(SCHOOLID, GRADE, ROOM, MPSID, LAST, FIRST, TESTDATE, TESTPHASE, WRIT1, WRIT2, WRIT3, WRIT_M, DATANOTE, LANG, PRIDWRIT1, PRIDWRIT2, PRIDWRIT3, SUBMITTER, DATASUBMIT, PROBLEV, DATAPOINTID) VALUES';
//add ", DATAPOINTID" back to the forgoing line once I've added that primary key to the probsolve DATAWRIT table, also add the '' back to the insert lines below
//THIS DOES NOT FILTER OUT BLANK ROWS LIKE I WISH IT WOULD
for ($i=0; $i<count($SCHOOLID); $i++) {
if ($i == 0)
$sql .= "('$SCHOOLID[$i]', '$GRADE[$i]', '$ROOM[$i]', '$MPSID[$i]', '$LAST[$i]', '$FIRST[$i]', '$TESTDATE[$i]', '$TESTPHASE[$i]', '$WRIT1[$i]', '$WRIT2[$i]', '$WRIT3[$i]', '$MED[$i]', '$DATANOTE[$i]', '$LANG[$i]', '$PRIDWRIT1[$i]', '$PRIDWRIT2[$i]', '$PRIDWRIT3[$i]', '$SUBMITTER[$i]', Now(), '', '') WHERE (('$WRIT1[$i]' Is Not Null) AND ('$WRIT2[$i]' Is Not Null) AND ('$WRIT3[$i]' Is Not Null))";
else
$sql .= ", ('$SCHOOLID[$i]', '$GRADE[$i]', '$ROOM[$i]', '$MPSID[$i]', '$LAST[$i]', '$FIRST[$i]', '$TESTDATE[$i]', '$TESTPHASE[$i]', '$WRIT1[$i]', '$WRIT2[$i]', '$WRIT3[$i]', '$MED[$i]', '$DATANOTE[$i]', '$LANG[$i]', '$PRIDWRIT1[$i]', '$PRIDWRIT2[$i]', '$PRIDWRIT3[$i]', '$SUBMITTER[$i]', Now(), '', '') WHERE (('$WRIT1[$i]' Is Not Null) AND ('$WRIT2[$i]' Is Not Null) AND ('$WRIT3[$i]' Is Not Null))";
}
// 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);
Perhaps I need to put some sort of filtering code between this page and the original submit form page? Or somehow drop every $ith element of the arrays if certain array values were left blank?