suvin_prathab Posted November 12, 2008 Share Posted November 12, 2008 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 Link to comment https://forums.phpfreaks.com/topic/132414-doubt-in-insert-statement-using-autoincrement-with-mysql_real_escape_string/ Share on other sites More sharing options...
redarrow Posted November 12, 2008 Share Posted November 12, 2008 Change NULL to '$autoid', Think that it then the database should increment by 1 each entry....... Link to comment https://forums.phpfreaks.com/topic/132414-doubt-in-insert-statement-using-autoincrement-with-mysql_real_escape_string/#findComment-688416 Share on other sites More sharing options...
PFMaBiSmAd Posted November 12, 2008 Share Posted November 12, 2008 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. Link to comment https://forums.phpfreaks.com/topic/132414-doubt-in-insert-statement-using-autoincrement-with-mysql_real_escape_string/#findComment-688432 Share on other sites More sharing options...
redarrow Posted November 12, 2008 Share Posted November 12, 2008 But will NULL still let him still get increments in the database............ Link to comment https://forums.phpfreaks.com/topic/132414-doubt-in-insert-statement-using-autoincrement-with-mysql_real_escape_string/#findComment-688448 Share on other sites More sharing options...
Mchl Posted November 12, 2008 Share Posted November 12, 2008 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) Link to comment https://forums.phpfreaks.com/topic/132414-doubt-in-insert-statement-using-autoincrement-with-mysql_real_escape_string/#findComment-688459 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.