View Single Post
  #1 (permalink)  
Old Nov 17th, 2005, 21:17
jswebdev jswebdev is offline
Junior Member
Join Date: Sep 2005
Location: kNot in Kansas
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
seeking cause for err: "Duplicate entry '' for key 2"

i've created a very simple data collection form. the MySQL db table has 6 fields. an auto_incrementing int for the primary key, then 3 varchars for first, last name, and e-mail, an INT for phone number, and a TEXT for comments.
the form has 5 fields, each appropriate for the datatype (including a <textarea> for the comments). the form is on index.php and its action goes to a file named thanks.php so i can confirm to the user that their info was in fact entered into the db by echoing back the $_POST data submitted by the form action.
i also have an IF statement set to check for existence of $_POST data sent from the form in a required field, Email-- since it's the critical bit of data, if it's empty, the index.php page is loaded again.
however, all of this is not working, and my error is "Duplicate entry '' for key 2"
here's the code from the thanks.php page, where most of the parsing takes place. the only thing on the other page is the form, and i always make it successfully to the thanks.php page.
PHP: Select all

<?php 

$conn 
mysql_connect("localhost""private""private");
mysql_select_db("seminar"$conn) or die(mysql_error());
if (
$_POST['EMAIL'] = "") {
$url "index.php";
header("Location: $url");
exit;
} else {
$inquery "INSERT into interest values ('', '$_POST[F_NAME]', '$_POST[L_NAME]', '$_POST[email]', 
'$_POST[PHONE]', '$_POST[REMARK]')"
;
mysql_query($inquery$conn) or die(mysql_error());
$htmlblock "<h3>the following was recorded by your entry:</h3>
<p>First Name: '$_POST[F_NAME]'</p>
<p>Last Name: '$_POST[L_NAME]'</p>
<p>e-Mail: '$_POST[email]'</p>
<p>Phone: '$_POST[PHONE]'</p>
<p>Remarks: '$_POST[REMARK]'</p>"
;
}
?>
<p>
<?php 
echo $htmlblock;
?>
</p>
i posted a similar thread in another php forum-- although it brought to my attention something about "addslashes" (which isn't represented here cause i wanted you to see my original code) but their solution didn't solve the problem anyway-- so i'm still stumped.
thanks for reading!!.

Last edited by jswebdev; Nov 17th, 2005 at 21:21.
Reply With Quote