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?😕

    Try this -

    <?
    
    $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
    
    // need extra counter as we might not enter all lines from the arrays
    $j = 0;
    
    //THIS DOES NOT FILTER OUT BLANK ROWS LIKE I WISH IT WOULD - IT SHOULD NOW
    for ($i=0; $i<count($SCHOOLID); $i++) {
    
    // add another if() to check that all required data has been inputted
    if ($SCHOOLID[$i] && $GRADE[$i] /* and so on, for all values you want to check */ ) {
    
    if ($j == 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))";
    	}
    // 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);
    
    ?>

    Haven't tested it but it should work 😉

      as an example, if you wanted just one specific field to not be empty:

      if ($j == 0) {
      if ($field_name != "") {
          $sql .= "(etc)";
      }
          } else {
      if ($field_name != "") {
          $sql .= ", (etc)";
      }
          }
      // increment counter
      $j++;
      

      If you wanted no empty fields use

      if ($j == 0) {
      if (($field_name1 != "") && ($field_name2 != "") && ($field_name3 != "")) {
          $sql .= "(etc)";
      }
          } else {
      if (($field_name1 != "") && ($field_name2 != "") && ($field_name3 != "")) {
          $sql .= ", (etc)";
      }
          }
      // increment counter
      $j++;
      

      Add as many as you need.

        I tried the suggestion from nnichols first. It worked great once I removed the "WHERE (('$WRIT1[$i]' Is Not Null) AND ('$WRIT2[$i]' Is Not Null) AND ('$WRIT3[$i]' Is Not Null))" from the $sql code.

        I have not yet tried the siwis approach but will tomorrow when I have more time.

        Thanks yet again folks!😃

          Sorry about that. I forgot about your WHERE clause.

          You can't use a WHERE clause in an INSERT statement (unless it is an INSERT... SELECT).

            In the problem above I was dealing with "AND" relationships (I take it that's what the "&&" characters reflect?) between the filter fields....what about "OR"?

              // add another if() to check that all required data has been inputted
              if ($SCHOOLID[$i] && $GRADE[$i] /* and so on, for all values you want to check */ ) {
              

              This is saying add the query values if there is a value for (SCHOOLID AND GRADE). So you just go on adding all the required fields to that if statement.

              If you want to add some ORs in there use '||' - 'double verticle pipe'. Remember to group sections of the condition in '()' to make sure the logic is correct -

              // add another if() to check that all required data has been inputted
              if ($SCHOOLID[$i] && $GRADE[$i] && ($this || $that) ) {
              

              Hope this helps 😉

                Thanks again. I finally found a print reference to this AND/OR, &&/|| business in one of the books I have (Larry Ullman's PHP for the World Wide Web (Peachpit, 2001))

                Although the code you gave me works great, I am struck by the lack of specifying the criteria that the array element has to be NULL at any point. Is that the default for this operation? I don't see anything that says a comparison should be made to NULL, Is Null, or "" or whatever. If I wanted to restrict the input to some specific non-null value (ie. only recording records where a score was, say, greater than 25) how would that be entered?

                $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';
                
                //THIS FILTERS OUT BLANK ROWS Thanks again to nnichols!
                // need extra counter as we might not enter all lines from the arrays
                $j = 0;
                
                for ($i=0; $i<count($SCHOOLID); $i++) {
                
                // add another if() to check that all required data has been inputted: Say the user did not enter any scores for the writing task, which is what this version of the form is all about....
                if ($WRIT1[$i] && $WRIT2[$i] && $WRIT3[$i]) {
                
                if ($j == 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(), '', '')";
                    }
                
                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(), '', '')";
                    }
                
                // 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");

                Hope I'm not being a pest...but I'm having such fun with this stuff!

                  If I wanted to restrict the input to some specific non-null value (ie. only recording records
                  where a score was, say, greater than 25) how would that be entered?

                  For this you would check -

                  if ($_POST['var_name'] > 25)

                  Hope this helps 😉

                    6 days later

                    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.

                      It has something to do with this part of the statement:

                      if ($DORF1WR[$i] && $DORF2WR[$i] && $DORF3WR[$i]) {

                      It has 3 conditions in it. If I have one or two, the insert query goes through, if it has 3, I get the error.

                      Any thoughts on this?😕

                        I went back and tried the method suggested by siwis a few posts back. The query runs with all of the conditions I had in mind...the problem is, all the rows with the blank cells still get entered into the database! (but when I look at the data table, the rows are filled in with zeros.

                        Here's my understanding of how to use the siwis code:

                        $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++) {
                        
                        if ($j == 0) {	
                        if (($DIBELS_IS_RAW !="") && ($DIBELS_IS_TIME !="") && ($DIBELS_WORD_USE !="") && ($DIBELS_LETTER_NAMING !="") && ($DIBELS_PHONEME_SEG !="") && ($DIBELS_NW !="") && ($DIBELS_RETELL !="") && ($DORF1WR !="") && ($DORF2WR !="") && ($DORF3WR !="")) {
                            $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(), '$PROBLEV[$i]','')";
                        }
                        	} else {
                        if (($DIBELS_IS_RAW !="") && ($DIBELS_IS_TIME !="") && ($DIBELS_WORD_USE !="") && ($DIBELS_LETTER_NAMING !="") && ($DIBELS_PHONEME_SEG !="") && ($DIBELS_NW !="") && ($DIBELS_RETELL !="") && ($DORF1WR !="") && ($DORF2WR !="") && ($DORF3WR !="")) {
                            $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(), '$PROBLEV[$i]','')";
                        }
                            }
                        // increment counter
                        $j++;
                        
                        } // 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);

                        Am I doing something wrong here? 🙁

                          Without testing your code my only guess is that the loop you are creating with

                          for ($i=0; $i<count($SCHOOLID); $i++) {

                          is failing to initiate. This could be (and its a wild guess) owing to your $i<count($SCHOOLID);

                          Give it another go, but this time try this slightly more longwinded way:

                          $end = sizeof($SCHOOLID);
                          $end = $end - 1;
                          for ($i = 0; $i <=$end; $i++)	{ 

                            Hi siwis;

                            I gave your suggestion a try, but that does not seem to be it. I am starting to wonder if it maybe has something to do with the nature of the MySQL data fields. In the $sql statement I stripped the single quotes off of the variable designators (ie. '$DORF1WR[$i]') where only numeric data should be entered into the table. All the MySQL table columns for those items are designated as int(11) Null/Yes, default=Null. Now the error message contains everything the way it is supposed to be going into the DB (Fieldnames, proper parentheses, commas, etc) AND the empty rows have been filtered out (that's progress at least). Right now I'm wondering if is something about the way I am submitting my TESTDATE field.

                            It's just so darn weird that it all works fine on the other similar forms and tables for this project. :mad:

                              so is the full sql now being generated correctly (ie it is appending new insert blocks if there are no empty fields?

                              I'll assume now then that you've moved on to a new problem.
                              What are the symptoms of the new problem? Do any records get inserted into the db?

                              Do you have field type conflicts with the data you are attempting to insert?

                              Have you tried echo'ing each line of the sql which gets generated in your loop out to make sure that it is being formatted/constructed as you intended?

                              I commonly revert to phpmyadmin for debugging my sql's. I write my php to echo its generated sql to screen, then copy and paste that sql into phpmyadmin. This often means that I pick up on syntax errors early and avoid lengthy debugging sessions.

                                Write a Reply...