I wasn't sure if this should be in the MySQL or PHP forum. I have a database to enter student info for a school (it's a detention list - I'm the VP) I have a form to update records in a database as each student is assigned detention. It only allows me to enter one student at a time. Is there a way to enter multiple students? For example if 20 students have detention, I want to enter 20 students into the database at once. (the database is for my tracking purposes)

<form id="form1" name="Update" method="post" action="add.php">
  First Name: <input type="text" name="fname" id="textfield" />
  <br />
  Last Name: <input type="text" name="lname" id="textfield2" />
<input name="" type="submit" value="send" />


$con = mysql_connect("localhost", "******", "*****");
if (!$con)
die('Could not connect to DB: ' . mysql_error() );

mysql_select_db ("*****", $con);

$sql="INSERT INTO items (fname, lname)
VALUES ('$_POST[fname]','$_POST[lname]')";

if (!mysql_query($sql,$con))
die ('Error: ' . mysql_error());
echo "Record added";


Also, is there a way to add a date to each entry automatically?
Thanks for any help

9 Years
Discussion Span
Last Post by kevinritt

I'm a newbie so I am a little lost. Here's what I want to do:
1. Students are assigned detention - say 10 students
2. I want to upload to my database those 10 names, the date.
3. I have a form that let's me upload one set of data (First name, last name)
4. Rather than do this 10 times, I want to use a form that let's me upload once
5. I understand the foreach loop (a little) but I'm not sure where to add it in relation to the sql 'insert' statement

Thanks again for your help


Typically in a web application, you would do this 10 times. It is possible to make 1 call, just depends what way you go about it.

What method are you thinking of storing all 10 at once, as far as how are you going to keep track of your 10 before you do the insert?


I was going to use a form but I guess it would be easier to write an INSERT INTO statement. I just to make it a from I could open on a web page. Detention is daily - the number will change from day to day. I'll keep a daily list (maybe it would be easier to upload as a CSV with multiple names?) I have the database set up to take all the info

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.