ladieballer2004 Posted August 23, 2009 Share Posted August 23, 2009 So I have a portion of my form that has three rows and four columns. The form is asking my users to enter activities or jobs they have been involved in. They have to fill in at least one row but they don't have to fill in all three. Right now my code entered all three even if a row was blank. So i put a while loop in it. It skips the empty row now but the loop won't stop. I tried using a for loop but I still have the same problem. Here is my code. //enter rows into database foreach($_POST['Activity'] as $row=>$Act) { while (!empty($_POST['Activity'])) { $Activity=($Act); $Position=($_POST['Position'][$row]); $StartDate=($_POST['StartDate'][$row]); $EndDate=($_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 "$i<br/>"; } } Here is my form: <body> <form action="insert.php" method="post"> <table width="77%"> <td height="63" colspan="5"><h3>Other involvement during high school, college (clubs, sports, work, volunteer, etc.): </h3></td> </tr> <tr> <td width="20%"><h3>Activity</h3></td> <td width="19%"><h3>Position</h3></td> <td width="23%"><h3>Start Date</h3></td> <td width="25%" height="60"><h3>End Date</h3></td> </tr> <tr> <td height="63"><input name="Activity[]" type="text" id="Activity[]" size="15" /> <td height="63"><input name="Position[]" type="text" id="Position[]" size="15" /> <td height="63"><input name="StartDate[]" type="text" id="StartDate[]" size="15" /> <td height="63"><input name="EndDate[]" type="text" id="EndDate[]" size="15" /> </tr> <tr> <td height="63"><input name="Activity[]" type="text" id="Activity[]" size="15" /> <td height="63"><input name="Position[]" type="text" id="Position[]" size="15" /> <td height="63"><input name="StartDate[]" type="text" id="StartDate[]" size="15" /> <td height="63"><input name="EndDate[]" type="text" id="EndDate[]" size="15" /> </tr> <tr> <td height="63"><input name="Activity[]" type="text" id="Activity[]" size="15" /> <td height="63"><input name="Position[]" type="text" id="Position[]" size="15" /> <td height="63"><input name="StartDate[]" type="text" id="StartDate[]" size="15" /> <td height="63"><input name="EndDate[]" type="text" id="EndDate[]" size="15" /> </table> <p> </p> <p> <input type="submit" name="Submit" id="Submit" value="Submit" /> </p> </form> </body> </html> Please Help. Thankyou in advance Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.