1

I am fairly new to sql and I've run into an error while trying to insert a row into a MySQL database. I am binding values before inserting to the database to prevent from sql injection.

My insert statement:

INSERT INTO member (FirstName, LastName, Date of Birth, Street Address, 
                   City, State, Zip, Email, Phone, Active)
VALUES (:FirstName, :LastName, :DateOfBirth, :streetAddress, :City, :State, 
                    :Zip, :Email, :Phone, :Active)

Is the primary key required in the insert statement? I do have it set to auto increment in the database.

The error I keep getting is:

1064 - 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 '"'FirstName', 'LastName', 'Date of Birth', 'Street Address', 'City', 'State', 'Z' at line 1

I've tried working around the syntax of the statement itself and I'm fairly certain it is syntactically correct although my sql knowledge is very very limited. Thank you for your time.

Tama198

3
  • in oracle when there is space in column name, we should include such in Double Quotes. But i am not sure about my sql Commented May 4, 2012 at 5:02
  • I had no idea about spaces in column names thanks. unfortunately, I tried once with quotes around the name, and a second time by removing the spaces in the column names itself. Both were unsuccessful. Commented May 4, 2012 at 5:10
  • Please share table structure also? Commented May 4, 2012 at 5:48

1 Answer 1

2

Try with

INSERT INTO member (FirstName, LastName, `Date of Birth`, `Street Address`, 
                   City, State, Zip, Email, Phone, Active)
VALUES (:FirstName, :LastName, :DateOfBirth, :streetAddress, :City, :State, 
                    :Zip, :Email, :Phone, :Active)

Please check your table column name "Date of Birth" and "Street Address". Is column name allow space!! I am doubt of it.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks sarwar026, however I removed the spaces for the column names in the database and changed my insert statement with no change in the error. Are there settings in phpmyadmin that need changed in order to insert new rows?
What is your primary key? is it an auto-incremented field?
My primary key was column ID. although I had to change it to auto-increment and it worked fine. I thought I had auto-increment set to ID and apparently it wasn't. Still trying to learn the database world. Thank you sarwar026 and madhu for your help. Very Grateful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.