gilbertsavier
07-08-2009, 04:00 AM
Hi,
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:
<form action="insert*.php" method="post">
<table width="77%">
<td height="6*" colspan="5"><h*>Other involvement during high school, college (clubs, sports, work, volunteer, etc.): </h*></td>
</tr>
<tr>
<td width="20%"><h*>Activity</h*></td>
<td width="**%"><h*>Position</h*></td>
<td width="2*%"><h*>Start Date</h*></td>
<td width="25%" height="60"><h*>End Date</h*></td>
</tr>
<tr>
<td height="6*"><input name="Activity[]" type="text" id="Activity[]" size="*5" />
<td height="6*"><input name="Position[]" type="text" id="Position[]" size="*5" />
<td height="6*"><input name="StartDate[]" type="text" id="StartDate[]" size="*5" />
<td height="6*"><input name="EndDate[]" type="text" id="EndDate[]" size="*5" />
</tr>
<tr>
<td height="6*"><input name="Activity[]" type="text" id="Activity[]" size="*5" />
<td height="6*"><input name="Position[]" type="text" id="Position[]" size="*5" />
<td height="6*"><input name="StartDate[]" type="text" id="StartDate[]" size="*5" />
<td height="6*"><input name="EndDate[]" type="text" id="EndDate[]" size="*5" />
</tr>
<tr>
<td height="6*"><input name="Activity[]" type="text" id="Activity[]" size="*5" />
<td height="6*"><input name="Position[]" type="text" id="Position[]" size="*5" />
<td height="6*"><input name="StartDate[]" type="text" id="StartDate[]" size="*5" />
<td height="6*"><input name="EndDate[]" type="text" id="EndDate[]" size="*5" />
</table>
<p> </p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit" />
</p>
</form>
Here is the insert*.php file
<?php
$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)
{
$Activity=$Act;
$Position=$_POST['Position'][$row];
$StartDate=$_POST['StartDate'][$row];
$EndDate=$_POST['EndDate'][$row];
}
//enter rows into database
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.')";
if (!mysql_query($involv,$con))
{
die('Error: ' . mysql_error());
}
echo "$row record added";
mysql_close($con)
?>
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:
<form action="insert*.php" method="post">
<table width="77%">
<td height="6*" colspan="5"><h*>Other involvement during high school, college (clubs, sports, work, volunteer, etc.): </h*></td>
</tr>
<tr>
<td width="20%"><h*>Activity</h*></td>
<td width="**%"><h*>Position</h*></td>
<td width="2*%"><h*>Start Date</h*></td>
<td width="25%" height="60"><h*>End Date</h*></td>
</tr>
<tr>
<td height="6*"><input name="Activity[]" type="text" id="Activity[]" size="*5" />
<td height="6*"><input name="Position[]" type="text" id="Position[]" size="*5" />
<td height="6*"><input name="StartDate[]" type="text" id="StartDate[]" size="*5" />
<td height="6*"><input name="EndDate[]" type="text" id="EndDate[]" size="*5" />
</tr>
<tr>
<td height="6*"><input name="Activity[]" type="text" id="Activity[]" size="*5" />
<td height="6*"><input name="Position[]" type="text" id="Position[]" size="*5" />
<td height="6*"><input name="StartDate[]" type="text" id="StartDate[]" size="*5" />
<td height="6*"><input name="EndDate[]" type="text" id="EndDate[]" size="*5" />
</tr>
<tr>
<td height="6*"><input name="Activity[]" type="text" id="Activity[]" size="*5" />
<td height="6*"><input name="Position[]" type="text" id="Position[]" size="*5" />
<td height="6*"><input name="StartDate[]" type="text" id="StartDate[]" size="*5" />
<td height="6*"><input name="EndDate[]" type="text" id="EndDate[]" size="*5" />
</table>
<p> </p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit" />
</p>
</form>
Here is the insert*.php file
<?php
$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)
{
$Activity=$Act;
$Position=$_POST['Position'][$row];
$StartDate=$_POST['StartDate'][$row];
$EndDate=$_POST['EndDate'][$row];
}
//enter rows into database
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.')";
if (!mysql_query($involv,$con))
{
die('Error: ' . mysql_error());
}
echo "$row record added";
mysql_close($con)
?>