View Single Post
  #2 (permalink)  
Old Nov 18th, 2005, 03:51
grahame grahame is offline
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: seeking cause for err: "Duplicate entry '' for key 2"

Use the longer form of insert that names the fields, and don't try to fiddle the auto_increment field:
Code: Select all
insert into interest (forename, surname, email, phone, comment) 
values ('$_POST[F_NAME]', '$_POST[L_NAME]', '$_POST[email]', 
'$_POST[PHONE]', '$_POST[REMARK]')
Not only is that clearer and more robust, but it will mean that your code will not break if you add a later (optionally supplied) column to the table later on.
Aside - your comment about addslashes noted. If your PHP is configured with magic quotes on (it is that way by default) the you don't want to add slashes as you put things into the database. If it's configured with magic quotes off, it's important to add slashes and to do so before you release your page to the world or you'll be exposed to an injection attack.
Reply With Quote