Doubt in INSERT statement (using autoincrement with mysql_r

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
suvin_prathab
Forum Newbie
Posts: 5
Joined: Wed Nov 12, 2008 7:38 am

Doubt in INSERT statement (using autoincrement with mysql_r

Post 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
madan koshti
Forum Commoner
Posts: 50
Joined: Fri Jun 06, 2008 4:25 am

Re: Doubt in INSERT statement (using autoincrement with mysql_r

Post 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.
suvin_prathab
Forum Newbie
Posts: 5
Joined: Wed Nov 12, 2008 7:38 am

Re: Doubt in INSERT statement (using autoincrement with mysql_r

Post 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...!!!!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Doubt in INSERT statement (using autoincrement with mysql_r

Post 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.
Post Reply