PHP multiple insert to MySQL database
Posted by:
cooldudefx
Date: February 11, 2006 07:44PM
I am trying to create a registration form for many people (single teacher registering multiple students). As such, I have about 100 name fields, some of which will not already be filled. When a person hits submit, I only want the fields that have been filled to be inputted.
<form method="post" action="enter_it.php">
<table width="100%" border="1">
<tr>
<td><p>Student Name 01
<input name="name1" type="text" size="40" />
<br />
Student Name 02
<input name="name2" type="text" size="40" />
<br />
Student Name 03
<input name="name3" type="text" size="40" />
<br />
Student Name 04
<input name="name4" type="text" size="40" />
<br />
Student Name 05
<input name="name5" type="text" size="40" />
<br />
...
<td><input type="submit" name="submit" value="Submit Information" />
All fields are not required, just use as many as you need. </td>
</tr>
</table>
<p> </p>
</form>
Inputs into
$query="INSERT INTO students (name,school) VALUES ('$_POST[name1]','$_POST[school]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
echo "Entered Name 1. <br>";
$query="INSERT INTO students (name,school) VALUES ('$_POST[name2]','$_POST[school]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
echo "Entered Name 2. <br>";
$query="INSERT INTO students (name,school) VALUES ('$_POST[name3]','$_POST[school]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
echo "Entered Name 3. <br>";
$query="INSERT INTO students (name,school) VALUES ('$_POST[name4]','$_POST[school]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
echo "Entered Name 4. <br>";
$query="INSERT INTO students (name,school) VALUES ('$_POST[name5]','$_POST[school]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
echo "Entered Name 5. <br>";
.
What would I add to the above query lines to make it only submit filled fields.
Thanks in advance,
cooldudefx