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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

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.