Having problems processing a form

Codes here !

Moderators: macek, egami, gesf

User avatar
amp
New php-forum User
New php-forum User
Posts: 15
Joined: Tue Apr 01, 2003 3:12 am
Location: Ireland
Contact:

Having problems processing a form

Postby amp » Tue Apr 08, 2003 5:39 am

Hi All
I have a form that a user fills out & it processed by a file called process.php, here is the part of my process.php I'm having trouble with:

Code: Select all

<?php
include("config.php");
include("header.php");

#Connect to MySQL
$dbh = mysql_connect ($dbhost, $dbuname, $dbpass) or die ( 'I cannot connect to the database because: ' . mysql_error());

#Connect to DB
mysql_select_db ($dbname) or die (mysql_error());

#Define Form Elements
#Bastardin form elements have to be in order!!!
$result = mysql_query ("INSERT INTO travel (prn, date, name, dir, purpose, sponsor, refund, what_refundable, flight_cost, subsis_cost, no_nights, depart_location, depart_time, out_flight, via_location, via_arrive, via_depart, arrive_location, arrive_time, arrive_flight, return_location, return_time, return_flight, via_location2, via_arrive2, via_depart2, depart_time2, arrive_time2, flight_num2, from, to, via) values ('".$_POST['prn']."','".$_POST['date']."','".$_POST['name']."','".$_POST['dir']."',
'".$_POST['purpose']."','".$_POST['sponsor']."','".$_POST['refund']."',
'".$_POST['what_refundable']."','".$_POST['flight_cost']."',
'".$_POST['subsis_cost']."','".$_POST['no_nights']."',
'".$_POST['depart_location']."','".$_POST['depart_time']."',
'".$_POST['out_flight']."','".$_POST['via_location']."',
'".$_POST['via_arrive']."','".$_POST['via_depart']."',
'".$_POST['arrive_location']."','".$_POST['arrive_time']."',
'".$_POST['arrive_flight']."','".$_POST['return_location']."',
'".$_POST['return_time']."','".$_POST['return_flight']."',
'".$_POST['via_location2']."','".$_POST['via_arrive2']."',
'".$_POST['via_depart2']."','".$_POST['depart_time2']."',
'".$_POST['arrive_time2']."','".$_POST['flight_num2']."','".$_POST['from']."',
'".$_POST['to']."','".$_POST['via']."')", $dbh) or die (mysql_error());

The error I get when I submit the form is this:

Code: Select all

You have an error in your SQL syntax near 'from, to, via) values ('','08-04-2003',' Aishling Davis','Assistant','','','',''' at line 1

Now here is where I am getting really confused. The form worked fine till I added in 'from, to & via'. I also created 3 new tables in my DB called 'from, to & via' so I dont see what the problem is.
My question is, do all the variables in my script have to be in the EXACT same order as they appear in my database???
Can anyone see what my problem is, I've been trying for hours & having no luck :cry:.

Thanks in advance for any replies!

User avatar
mammal
New php-forum User
New php-forum User
Posts: 37
Joined: Wed Apr 02, 2003 1:31 am
Location: Hythe, UK

SQL Reserved Words

Postby mammal » Tue Apr 08, 2003 9:25 am

Hi Amp, your script looks fine but I'm pretty sure that "From" and "To"
are SQL reserved words. This means you cant name databases, tables or
columns "from" or "to". Try renaming those columns and see what happens, I'm
pretty sure it will work. I had the same problem six months ago when I tried
to call a TIMESTAMP column "time", it didnt like that one bit....

For more information on SQL reserved words visit:

http://www.jsoftware.com/books/help/user/sql_reserved_words.htm

Let me how you get on mate.

User avatar
amp
New php-forum User
New php-forum User
Posts: 15
Joined: Tue Apr 01, 2003 3:12 am
Location: Ireland
Contact:

Postby amp » Tue Apr 08, 2003 9:57 am

Thats it, I changed the names of from & to & it worked :D Thank you :wink:
Thanks for the link aswell, I was looking for something like that earlier.

Just 1 more question, say I have the 5th field in my DB called purpose, do I need to have purpose & $POST_[purpose] both 5th in my process.php script?? I think I do.

Cheers

User avatar
mammal
New php-forum User
New php-forum User
Posts: 37
Joined: Wed Apr 02, 2003 1:31 am
Location: Hythe, UK

Yup

Postby mammal » Tue Apr 08, 2003 10:14 am

Yeah you do! Otherwise the SQL wouldn't know where to put it.

By the way, do you use an SQL front-end like phpMyAdmin. Its easily compilable and is useful for testing scripts.

Check this out sometime:

http://www.phpmyadmin.net/

Glad your code works now...

Mammal

User avatar
amp
New php-forum User
New php-forum User
Posts: 15
Joined: Tue Apr 01, 2003 3:12 am
Location: Ireland
Contact:

Postby amp » Tue Apr 08, 2003 10:41 am

Yeah you do! Otherwise the SQL wouldn't know where to put it.

I thought so, but I just had to ask to make sure.

By the way, do you use an SQL front-end like phpMyAdmin. Its easily compilable and is useful for testing scripts.

Yep, I sure do, I've phpMyAdmin2.4.0 & I couldnt do without it, it's great :mrgreen:

Thanks again for your help, I'm really starting to get the hang of PHP & MySQL now :)


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron