Page 1 of 1

Doubt in INSERT statement (using autoincrement with mysql_r

Posted: Wed Nov 12, 2008 7:43 am
by suvin_prathab
I want to know how to use autoincrement data with mysql_real_escape_string.

I have created a signup page. Every thing workred fine before adding a field with primary key and auto_increment called autoid[/b].

The current statement looks like this

$query2 = sprintf("INSERT INTO members
(autoid,username,password,confirm_pass,email,confirm_email,security_q,answer,)
VALUES (NULL,'%s','%s','%s','%s','%s','%s')",
mysql_real_escape_string($username,$connection),
mysql_real_escape_string($hash,$connection),
mysql_real_escape_string($hash1,$connection),
mysql_real_escape_string($email,$connection),
mysql_real_escape_string($confirm_email,$connection),
mysql_real_escape_string($security_q,$connection),
mysql_real_escape_string($answer,$connection));


Error it show is

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 ') VALUES (NULL<'suvin_prathab','a6b079d410b330cf262d2610522f8dd2bf25df1a',' at line 2

Re: Doubt in INSERT statement (using autoincrement with mysql_r

Posted: Wed Nov 12, 2008 7:52 am
by madan koshti
Try

$query2 = sprintf("INSERT INTO members
(username,password,confirm_pass,email,confirm_email,security_q,answer,)
VALUES ('%s','%s','%s','%s','%s','%s','%s')",
mysql_real_escape_string($username,$connection),
mysql_real_escape_string($hash,$connection),
mysql_real_escape_string($hash1,$connection),
mysql_real_escape_string($email,$connection),
mysql_real_escape_string($confirm_email,$connection),
mysql_real_escape_string($security_q,$connection),
mysql_real_escape_string($answer,$connection));

PS: Dont insert PK as null.

Re: Doubt in INSERT statement (using autoincrement with mysql_r

Posted: Thu Nov 13, 2008 12:15 am
by suvin_prathab
If i give as u said it shows this error...?


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 ') VALUES ('suvin_prathab','a6b079d410b330cf262d2610522f8dd2bf25df1a','a6b0' at line 2



Can anyone please clear this...!!!!

Re: Doubt in INSERT statement (using autoincrement with mysql_r

Posted: Thu Nov 13, 2008 12:36 am
by requinix
If you actually looked at it you might see the problem. Unless, of course, you weren't aware that the last item in a list shouldn't have a comma after it.