dhtseany
August 6th, 2007, 04:18 PM
Hi all, got a new one. Everytime I try to insert data into mysql I get this following error:
Duplicate entry '' for key 2
The first time I try to add the info, it goes through without a problem. However, when I try to continue and add the next piece of info, the error pops up and continues to annoy me until I delete the data that went in fine the first time. Please note this is happening in both MySQL and the PHP code I first ran into this problem with.
Here is the PHP code that is generating the error:
<?php
include "add_cc.php";
if(isset($_POST['submit']))
{
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$coname=$_POST['coname'];
if(strlen($firstname)<1)
{
print "You did not enter a URL.";
}
else if(strlen($lastname)<1)
{
print "You did not enter a button.";
}
else if(strlen($coname)<1)
{
print "Problem with company name.";
}
else
{
$insertbutton=("INSERT into user (FirstName, LastName, coname) values('$firstname','$lastname','$coname')");
mysql_query($insertbutton) or die(mysql_error());
print "Added information. Click <a href='add.php'>here</a> to continue.";
}
}
else
{
print "<form action='add.php' method='post'>";
print "Company Name:<br>";
print "<input type='text' name='coname' size='20'><br>";
print "First Name:<br>";
print "<input type='text' name='firstname' size='20'><br>";
print "Last Name:<br>";
print "<input type='text' name='lastname' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>
Any ideas?
Thanks,
Sean
Duplicate entry '' for key 2
The first time I try to add the info, it goes through without a problem. However, when I try to continue and add the next piece of info, the error pops up and continues to annoy me until I delete the data that went in fine the first time. Please note this is happening in both MySQL and the PHP code I first ran into this problem with.
Here is the PHP code that is generating the error:
<?php
include "add_cc.php";
if(isset($_POST['submit']))
{
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$coname=$_POST['coname'];
if(strlen($firstname)<1)
{
print "You did not enter a URL.";
}
else if(strlen($lastname)<1)
{
print "You did not enter a button.";
}
else if(strlen($coname)<1)
{
print "Problem with company name.";
}
else
{
$insertbutton=("INSERT into user (FirstName, LastName, coname) values('$firstname','$lastname','$coname')");
mysql_query($insertbutton) or die(mysql_error());
print "Added information. Click <a href='add.php'>here</a> to continue.";
}
}
else
{
print "<form action='add.php' method='post'>";
print "Company Name:<br>";
print "<input type='text' name='coname' size='20'><br>";
print "First Name:<br>";
print "<input type='text' name='firstname' size='20'><br>";
print "Last Name:<br>";
print "<input type='text' name='lastname' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>
Any ideas?
Thanks,
Sean