3

I am trying to make a mysql insert like this one here

<http://www.w3schools.com/php/php_mysql_insert.asp >  
     INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) 

I am trying to insert the values below into the table userbase.

54007033331, Codi Y, Male, pub, http://google.com/ggg.jpg


INSERT INTO userbase (id,name,gender,publicity,pic) VALUES (54007033331, Codi Y, Male, pub, http://google.com/ggg.jpg)

MySQL query failed: 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 'Y, Male, pub, http://google.com/ggg.jpg)' at line 1

Can anyone please point me in the right direction of how to fix this syntax error?

1
  • 1
    Dude, strings needs to be quoted in mysql (and most other languages). Commented Feb 15, 2012 at 0:14

3 Answers 3

8

You should quote properly string and char values in query.

 INSERT INTO userbase (id,display,gender,publicity,pic) 
 VALUES (54007033331, 'Codi Y', 'Male', 'pub', 'http://google.com/ggg.jpg')
Sign up to request clarification or add additional context in comments.

Comments

1

Yeah, put quotes around String values.

Comments

1

Without knowing your column types I can't be sure, but I would hazard a guess that the values for all bar the first column are strings and the values need to be quoted with single quotes:

INSERT INTO userbase (id,display,gender,publicity,pic)
    VALUES (54007033331, 'Codi Y', 'Male', 'pub', 'http://google.com/ggg.jpg')

Though if you're doing this programmatically, you should be using placeholders:

INSERT INTO userbase (id,display,gender,publicity,pic)
    VALUES (?, ?, ?, ?, ?)

and value binding.

Comments

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.