Error that doesn't exist!!!! <---------------------

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ykarmi
Forum Commoner
Posts: 35
Joined: Mon Oct 30, 2006 4:45 pm

Error that doesn't exist!!!! <---------------------

Post by ykarmi »

Hey guys,
I get the following error:

Code: Select all

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 ''fname', 'lname', 'address', 'city', 'zipcode', 'amount') VALUE: INSERT INTO tbuserinfo ('fname', 'lname', 'address', 'city', 'zipcode', 'amount') VALUES (John, Doe, 1 Main St, San Jose, 95131, 1.00)

Here's my original line:

Code: Select all

$query = "INSERT INTO tbuserinfo ('fname', 'lname', 'address', 'city', 'zipcode', 'amount') VALUES ($firstName, $lastName, $address1, $city, $zip, $amount)";
Can you spot anything wrong with it? Because I can't :S
Thanks a lot!
Yuval :D
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

It's the quotes -- use backticks (above the left tab key) for field names (if anything), and single quotes for variables:

Code: Select all

$query = "INSERT INTO tbuserinfo (`fname`,`lname`,`address`,`city`,`zipcode`,`amount`) VALUES ('{$firstName}','{$lastName}','{$address1}','{$city}','{$zip}','{$amount}')";
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

also, please don't add <------------------------------ to your thread title. This is not going to get people to respond sooner. This community responds very fast as it is. More than likely this will only irritate people.
Post Reply