Jump to content

#1062 - Duplicate entry '0' for key 1


ana1020

Recommended Posts

hi,

 

i wrote a php script which is sitting on my server. i also created a table called INQUIRIES using phpMyAdmin. I get no errors when I run my php code, but the INSERT INTO statements do not seem to work. nothing gets inserted into the table INQUIRIES. when i try manually inserting content into the table through phpMyAdmin, i get this error:

 

#1062 - Duplicate entry '0' for key 1

 

did i build my table wrong? what does this error mean? how can i store my $_POST variables in this table without getting an error?

 

the table was built like this :

mysql> create table inquiries (  
    -> inquiries_id int primary key auto_increment not null,
    -> lastname varchar (20) not null,   
    -> firstname varchar (15) not null,   
    -> contactinfo varchar (30) not null,   
    -> subject varchar (50) not null,    
    -> comments blob not null);

 

and my php code looks like this :

 


//CONNECT TO DATABASE				
$dbhost = 'localhost';
$dbuser = 'ana1020';
$dbpass = '86bohuvt23';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');				
$dbname = 'fatcat';
mysql_select_db($dbname);

//IF THE SUBMIT BUTTON IS PRESSED, CHECK POST FIELD FOR DATA 		
if (isset($_POST['submit'])) {

//FOR THOSE WHO ENTERED EMAILS ADDRESSES AS THEIR CONTACT INFORMATION	 				
if ((!empty($_POST['firstname'])) && (!empty($_POST['lastname'])) && (!empty($_POST['subject'])) && (!empty($_POST['email'])) && (!empty($_POST['comments']))){
	$firstname = $_POST['firstname']; 
	$lastname = $_POST['lastname']; 
	$subject = $_POST['subject']; 
	$email = $_POST['email']; 
	$comments = $_POST['comments']; 
	$insertdata = "INSERT INTO inquiries (lastname, firstname, contactinfo, subject, comments) VALUES ('$lastname', '$firstname', '$email', '$subject', '$comments')";
	mysql_query($insertdata);

                //FORWARD INFORMATION TO MY PERSONAL EMAIL ACCOUNT
	$to = 'example@gmail.com';
	$subject = $subject;
	$message = $comments . "\n" . $firstname . ' ' . $lastname .  "\n" . $email;
	$headers = 'From: inquiries@example.com' . "\r\n" .
	'Reply-To: ' . $email . "\r\n" .
	'X-Mailer: PHP/' . phpversion();
	mail($to, $subject, $message, $headers);
	print "Thank you for your post<b> $firstname! </b><br />\n";
	print "We will get back to you promptly. <b>";
} 
//FOR THOSE WHO ENTERED PHONE NUMBERS 
elseif ((!empty($_POST['firstname'])) && (!empty($_POST['lastname'])) && (!empty($_POST['subject'])) && (!empty($_POST['phone'])) && (!empty($_POST['comments']))){ 
	$firstname = $_POST['firstname']; 
	$lastname = $_POST['lastname']; 
	$subject = $_POST['subject']; 
	$phone = $_POST['phone']; 
	$comments = $_POST['comments']; 
	$insertdata = "INSERT INTO inquiries (lastname, firstname, contactinfo, subject, comments) VALUES ('$lastname', '$firstname', '$phone', '$subject', '$comments')";
	mysql_query($insertdata);

	//FORWARD INFORMATION TO MY PERSONAL EMAIL ACCOUNT
	$to = 'example@gmail.com';
	$subject = $subject;
	$message = $comments . "\n" . $firstname . ' ' . $lastname . "\n" . $phone;
	$headers = 'From: inquiries@ana-carters.com' . "\r\n" .
	'Reply-To: noEmailProvided@example.com' . "\r\n" .
	'X-Mailer: PHP/' . phpversion();
	mail($to, $subject, $message, $headers);
	print "Thank you for your post<b> $firstname! </b><br />\n";
	print "We will get back to you promptly! <b>";
} else { print "Please enter first and last name, a subject and message, and an email or phone number where you can be reached. <br/>";} 					
}

print "</b><br />\n";
mysql_close($conn);

 

 

any thoughts? thanks!!!!

 

- ana

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.