Tama198
Tama198

Reputation: 29

sql insert keeps getting error

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

Upvotes: 1

Views: 190

Answers (1)

sarwar026
sarwar026

Reputation: 3821

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.

Upvotes: 2

Related Questions