Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 10-06-2008, 07:28 PM   #1 (permalink)
Registered User
 
Join Date: Sep 2008
Posts: 18
OS: WindowsXP SP3


Help me troubleshoot/tweak my PHP code

Inserting Multiple Rows - MySQL PHP Page.

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 moemnt I've got both the PHP code and the HTML form on one page, but I will change this)

PHP Code:
<?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>

VICTORIA:
<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.
CookieD89 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 10-07-2008, 02:21 AM   #2 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros


Re: Help me troubleshoot/tweak my PHP code

Hey, i have an answer for your first question:

a) just use a regular select element:
Code:
<select name="state">
<option value="VIC">VIC</option>
<option value="NSW">NSW</option>
<!-- and so on... -->
</select>
That wont allow the user to mess up your queries, it will take you a little longer coding and copying, etc.

As for posting multiple rows in one click, i've done something along the lines of this using javascript, basically you add to the form dynamically and check for each of the posted items... The process would be adding a button which add's a new row (state+hours) then when the form's submitted parse them all... If you want me to go through this please post back saying so.

Cheers,
Jamey
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 04:57 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85