Sorry for all the questions. I'm having trouble inserting multiple rows into the MySQL DB via a PHP/HTML form.
I've got a table setup like so -
Table name - timesheet
Columns - id (auto increment)
uname -
entrydate
state
hours.
And I'm trying to get a HTML form working with PHP so that they can insert into the database.
Right now I've got it sort of working with the code below (At the moment I've got both the PHP code and the HTML form on one page, but I will change this):
<?include_once ("auth.php");
include_once ("authconfig.php");
include_once ("check.php"); ?>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test-auth", $con);
$sql="INSERT INTO timesheet (uname, entrydate, state, hours)
VALUES
('$_POST[uname]','$_POST[entrydate]','$_POST[state]','$_POST[hours]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "meh";
mysql_close($con)
?>
<html>
<body>
<form action="test1.php" method="post">
<input type="hidden" name="uname" value="<?echo $check["uname"]?>" />
Entry Date: <input type="date" name="entrydate" />
Hours: <input type="text" name="hours" />
State: <input type="text" name="state" />
<input type="submit" />
</form>
</body>
</html>
The problems I have with this form is that -
a) The STATE input box is just for text, what i'm after is a drop down list so that users can only select from VIC, NSW, TAS, QLD, WA, etc. If somebody goes and types in for example 'VIC." with a fullstop or a space or something like VICTORIA, it's going to **** up all my other queries later on.
b) This form only works for putting in one row, what I want is to be able to have a form that can insert multiple rows with a single click. Eg -
$uname sent to the 'uname' column (Hidden) (I have a login/authentication system in place so once they're logged in it just ads their name in)
At the Top - [Datebox] [Clickable Calander to set date]
Then below -
STATE HOURS
VIC x.x
WA x.x
TAS x.x
QLD x.x
TAS x.x
[SUBMIT]
So this way it'd put in the amount of hours they do for each state.
uname=test entrydate- 2008-08-10 state=VIC hours=2.4
uname=test entrydate- 2008-08-10 state=WA hours=3.8
Is this possible?
Have been looking up arrays and loops but all the examples I've found are too techncial and I have a hard time adjusting it to work for me.