will2002 Posted October 20, 2008 Share Posted October 20, 2008 Hi I am developing an application that stores weekly working hours for employees. i currently have a form which takes in an employees timesheet and saves it to a database. The problem is that the form i have created only allows one employee entry to be submitted at a time. I need to be able to enter rows of employee data for all employees the same as you would in an excel spreadsheet and have the submit button enter the entire form with all the employees data. i am assuming it would probably involve an array and a for or while loop to run through the rows but im not really sure how to go about it. Im not asking anyone to do it for me just a nudge in the right direction. thanks in advance. Quote Link to comment Share on other sites More sharing options...
will2002 Posted October 20, 2008 Author Share Posted October 20, 2008 Below is some code showing the basic layout of what im trying to do. once the button is pressed the while loop should continue to run the insert query until all the rows are done ie 3 rows in the sample code below. I know there is extra code needed to get the sql query to continually run within the while loop but im not really sure what to include. I may be dooing it totally wrong so im open to any suggestions Quote Link to comment Share on other sites More sharing options...
will2002 Posted October 20, 2008 Author Share Posted October 20, 2008 Sorry forgot to add the code <html> <body> <table border="2" bgcolor="#3399FF" cellpadding="1" cellspacing="1"> <form name='form1' method='post' action='formloop.php'> <input type='submit' name='save' value='Submit'> <?php $a=0; while ($a <= "2"){ echo"<tr><td><input type='text' name='enum'></td> <td><input type='text' name='ename' size='2'></td> <td><input type='text' name='time'></td> <td><input type='text' name='timehalf'></td> <td colspan='0' align = center> </td> </tr>"; $a++; } ini_set('display_errors', 1); error_reporting(E_ALL & ~E_NOTICE); if(isset($_POST['save'])){ if($dbc = @mysql_connect('localhost', '', '')){ if(!$dbc = @mysql_select_db('employees')){ die("<p> Could not select the database because:'.mysql_error().'</p>"); } } $b=0; while ($b <= "2"){ $query = "INSERT INTO timesheet (num, name, norm, normhalf) VALUES ('{$_POST['enum']}', '{$_POST['ename']}', '{$_POST['time']}', '{$_POST['timehalf']}'"; $b++; if(@mysql_query ($query)){ print "<p align='center'>The timesheet has been saved</p>"; } else{ print"<p align='center'>Sorry. Unable to save details.</p>"; } } } ?> </form> </table> </body> </html> 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.