Jump to content

spreadsheet form


will2002

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/129266-spreadsheet-form/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/129266-spreadsheet-form/#findComment-670384
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/129266-spreadsheet-form/#findComment-670386
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.