Jump to content

Doubt in INSERT statement (using autoincrement with mysql_real_escape_string)


suvin_prathab

Recommended Posts

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

The part of the error message immediately after the single-quote in - the right syntax to use near 'xxxxxx is the point where mysql could not figure out what you were doing. If you look at your query immediately before the ') VALUES...' that was mentioned in the error message, you will notice that there is an extra comma there.

It will. But in fact he can drop it altogether from both columns and values part of the statement

 

INSERT INTO members
(username,password,confirm_pass,email,confirm_email,security_q,answer)
VALUES ('%s','%s','%s','%s','%s','%s')

 

Also note, that there's one value missing (there are seven columns, but only six values)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.