Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEED HELP INSERTING VALUES TO DATABASE

Status
Not open for further replies.

liquidtrax

Programmer
Feb 13, 2005
8
GB
I get this error

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'long, talk, date, type, own, e, style, P) VALUES ( 'o','o','o'

The code extract is below

//insert into table
$query = "INSERT INTO data (firstname, lastname, street, town, city, postcode, country, email, phone, nickname, salary, drive, vehicle, travel, long, talk, date, type, own, e, style, P)
VALUES( '$first_name','$last_name','$street', '$town', '$city', '$postcode', '$country', '$email', '$phone', '$nickname', '$salary', '$drive', '$vehicle', '$travel', '$long', '$talk', '$date', '$type', '$own', '$e', '$style', 'U');";
$query = mysql_query($query) or die(mysql_error());
mysql_close($link);

Can anyone spot a bug? would be real helpful if someone could tell me where ive gone wrong
 
Try echoing the contents of $query to the page (rather than attempting any inserts or database activity at all). Maybe there is something odd in the data that is causing your problem? Try cutting down the length of the insert to just one or two fields as you debug the problem.

Personally I would avoid using those variable names that sound like reserved words ($date, $type and $e) and confirm that the data types in your table reflect the correct types for the data you are supplying.

This is all common sense... but others may have a similar to you and gain some benefit from your post.

Jeff
 
yes all of the data works when been echoed. I had the script working, then I added several more fields to the database and it seems to have caused an error.

I have changed variable names and it has made no difference and all data types are correct.

I have tried using only 1 character to test the insert but it does not work either

any other ideas?
 
Have you tried embedding your database columns in backquotes to avoid reserved works?
Code:
$query = "INSERT INTO `data` (`firstname`, `lastname`, `street`, `town`, `city`, `postcode`, `country`, `email`,  `phone`, `nickname`, `salary`, `drive`, `vehicle`, `travel`, `long`, `talk`, `date`, `type`, `own`, `e`, `style`, `P`)
VALUES( '$first_name','$last_name','$street', '$town', '$city', '$postcode', '$country', '$email', '$phone', '$nickname', '$salary', '$drive', '$vehicle', '$travel', '$long', '$talk', '$date', '$type', '$own', '$e', '$style', 'U');";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top