Jump to content

Insert Multiple Rows Into A Mysql Table Using Php Array


Recommended Posts


I have a form that asks the applicant for previous involvement. They have the option of entering up to three rows and after they press submit the computer needs to enter possible multiple rows. Here is my form code:


Other involvement during high school, college (clubs, sports, work, volunteer, etc.):



Start Date

End Date












Here is the insert1.php file


$con = mysql_connect("localhost","Application","*******");

if (!$con)


die('Could not connect: ' . mysql_error());



mysql_select_db("CpaApp", $con);



//Assign each array to a variable

foreach($_POST['Activity'] as $row=>$Act)









//enter rows into database

foreach($_POST['Activity'] as $row=>$Act)









$involv = "INSERT INTO Involvement (Activity, Position, StartDate, EndDate)

VALUES ('.$Activity.','.$Position.','.$StartDate.','.$EndDate.')";



if (!mysql_query($involv,$con))


die('Error: ' . mysql_error());


echo "$row record added";





Thanks & regards



[Link Deleted]

Edited by Andrea
Link to comment
Share on other sites

Is this what you wanted? Then will each one beome it's own row in the database.

Hope it helps.


foreach($_POST['Activity'] as $row=>$Act)
   $Activity = mysql_real_escape_string($Act); 
   $Position = mysql_real_escape_string($_POST['Position'][$row]);
   $StartDate = mysql_real_escape_string($_POST['StartDate'][$row]);
   $EndDate = mysql_real_escape_string($_POST['EndDate'][$row]);

   $involv = "INSERT INTO Involvement(Activity, Position, StartDate, EndDate)
              VALUES('$Activity', '$Position', '$StartDate', '$EndDate')";


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...