Forum Moderators: open

Message Too Old, No Replies

INSERT query failing, PHP

New to PHP, newer to SQL, be gentle

         

gothwalk

5:34 pm on Nov 4, 2006 (gmt 0)

10+ Year Member



Having a bit of a problem here; the SQL syntax is correct, as far as I can see, but something isn't happy.

Database connection is working fine (I can run SELECTs with no trouble), so I don't think it's that.

Here's the code:

$query = "INSERT INTO users 
(userid, username, password, name, regdate, email, website, location, show_email, last_login, desc)
VALUES
(NULL,'goddwalk','pa55word', 'Test User', '20061104', 'user@test.com', 'www.test.com', 'Dublin', '0', '20061104', 'Woof woof, man')";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

Any ideas?

... and here's the returned error:

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 'desc) VALUES (NULL,'goddwalk','pa55word', 'Test User', '20061104', 'user@test.' at line 2

Mohamed

6:57 pm on Nov 4, 2006 (gmt 0)

10+ Year Member



(NULL,'goddwalk','pa55word', 'Test User', '20061104', 'user@test.com', 'www.test.com', 'Dublin', '0', '20061104', 'Woof woof, man')";

you are inserting NULL value into userid. so if your userid field is integer you need to insert integer value not a null.

[edited by: Mohamed at 6:59 pm (utc) on Nov. 4, 2006]

FalseDawn

8:49 pm on Nov 4, 2006 (gmt 0)

10+ Year Member



The error is actually caused by your choice of naming a column "desc", which is a reserved word in mySQL, used to order results.

I'd suggest changing the column name.

If you are trying to insert a NULL into a non-null field, the error will be something like "column #*$!x cannot be NULL"

gothwalk

12:07 am on Nov 5, 2006 (gmt 0)

10+ Year Member



Excellent, thanks!