Jump to content


Photo

error message:Duplicate entry '' for key 1


  • Please log in to reply
4 replies to this topic

#1 davina

davina
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • Locationchicago

Posted 05 July 2004 - 05:55 PM

i have written a php script that inserts values from a form into a table in a mysql db. upon submitting the form i get the error message" Duplicate entry '' for key 1".
i have no idea what this message means, but i have looked at the form and my query and i dont have any duplicate variable names. can someone please point in the right direction? the php code is below..thanx
davina

<?php
// connecting to the mysql and selecting the proper database
$conn = mysql_connect("DAVINA","davina zedan", null) or die(mysql_error());
mysql_select_db("test",$conn) or die(mysql_error());
//create and issue query
$addSafe=" insert into safe_db
(serialNum, model,enteredBy, dateEntered, location, lastModified, lockType, combination, overrideCode, programmerCode, user1, user2, user3,
user4, user5, user6, user7, user8, user9)
values
('$_POST[serialNum]', '$_POST[model]', now(), '$_POST[enteredBy]',
now(), '$_POST[location]', '$_POST[lockType]', '$_POST[combination]', '$_POST[overrideCode]', '$_POST[programmerCode]', '$_POST[user1]',
'$_POST[user2]', '$_POST[user3]', '$_POST[user4]', '$_POST[user5]', '$_POST[user6]', '$_POST[user7]', '$_POST[user8]', '$_POST[user9]') ";

mysql_query($addSafe, $conn) or die(mysql_error());
//message for user
$msg="The safe $serialNum has been added!";
?>

<html>
<head>
<title>Adding Safe to System</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php print $msg; ?>
</body>
</html>


#2 davina

davina
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • Locationchicago

Posted 05 July 2004 - 06:22 PM

ok..i figured out that the error. serialNum is the primary key and for some reason in the insert its not pulling the values from the previous form...it is inserting a blank space into the database. so i got the error message because when i reran the script, it again did not pull the variable from the previous form and tried to put a blank space for serialNum in the db. can anyone tell me why it is not pulling all of my variables? its grabbing some. the code for the form is below..i have already posted the code for the php script. thanx again
davina
<body>
<p align="right"><form name="button" action="safeSearchForm.php"><input type="submit" value ="New Search" ></form>
<form name="addSafeForm" action="addSafe.php">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="2">
<tr align="left" valign="top" bgcolor="#006699">
<td colspan="2"><b class="style1">General Information </b></td>
</tr>
<tr><input type= "hidden" name="id1" value="$id1"></tr>
<tr><input type= "hidden" name="id" value="$id"></tr>
<tr align="left" valign="top">
<td><b>Serial number: </b></td>
<td width="62%"><input type="text" name="serialNum"></td>
</tr>
<tr align="left" valign="top">
<td width="38%"><b>Model Number : </b></td>
<td width="62%"><input type="text" name="model"></td>
</tr>
<tr align="left" valign="top">
<td width="38%"><b>Date Created:</b></td>
<td width="62%"><input type="text" name="dateEntered"></td>
</tr>
<tr align="left" valign="top">
<td width="38%"><b>Created By:</b></td>
<td width="62%"><input type="text" name="enteredBy"></td>
</tr>
<tr align="left" valign="top">
<td><b>Last Modified:</b></td>
<td><input type="text" name="lastModified"></td>
</tr>
<tr align="left" valign="top">
<td><b>Location:</b></td>
<td><input type="text" name="location"></td>
</tr>
<tr align="left" valign="top">
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr align="left" valign="top" class="style1">
<td colspan="2" class="style1">Lock Information </td>
</tr>
<tr align="left" valign="top">
<td><b>Lock Type:</b></td>
<td><input type="text" name="lockType"></td>
</tr>
<tr align="left" valign="top">
<td><b>Combination:</b></td>
<td><input type="text" name="combination"></td>
</tr>
<tr align="left" valign="top">
<td class="style3">Override Code:</td>
<td><input type="text" name="overrideCode"></td>
</tr>
<tr align="left" valign="top">
<td><b>Programmer Code: </b></td>
<td><input type="text" name="programmerCode"></td>
</tr>
<tr align="left" valign="top">
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr align="left" valign="top">
<td colspan="2" class="style1">Additional Information </td>
</tr>
<tr align="left" valign="top">
<td><b>User 1 </b></td>
<td><input type="text" name="user1"></td>
</tr>
<tr align="left" valign="top">
<td><b>User 2 </b></td>
<td><input type="text" name="user2"></td>
</tr>
<tr align="left" valign="top">
<td><b>User 3 </b></td>
<td><input type="text" name="user3"></td>
</tr>
<tr align="left" valign="top">
<td><b>User 4 </b></td>
<td><input type="text" name="user4"></td>
</tr>
<tr align="left" valign="top">
<td><b>User 5 </b></td>
<td><input type="text" name="user5"></td>
</tr>
<tr align="left" valign="top">
<td><b>User 6 </b></td>
<td><input type="text" name="user6"></td>
</tr>
<tr align="left" valign="top">
<td><b>User 7 </b></td>
<td><input type="text" name="user7"></td>
</tr>
<tr align="left" valign="top">
<td><b>User 8 </b></td>
<td><input type="text" name="user8"></td>
</tr>
<tr align="left" valign="top">
<td><b>User 9 (Override) </b></td>
<td><input type="text" name="user9"></td>
</tr>
</table>
<p align="center" class="style1">------End File------</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><center>
<input type="submit" value="Add Safe to System" > </input>
</center></td>

</tr>
</table> </form>
<p align="center">&nbsp;</p>
</body>

#3 davina

davina
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • Locationchicago

Posted 06 July 2004 - 03:02 PM

OMFG
i am the queen of stupidity..i forgot to put method="post" in my form tag..
thanks to everyone for your help..sorry i wasted your time!
It all werks now
thanx again
davina

#4 colin2003

colin2003
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationCanada

Posted 08 July 2004 - 11:28 PM

Not to be rude davina, but have you realized that the only posts in this topic were your own? Thanks for the help? Sorry...had to get that out. At least you solved your problem. :D

#5 davina

davina
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • Locationchicago

Posted 09 July 2004 - 12:04 PM

actually had a few people from the board help me off the board on this....i dont usully carry on convos by myself on boards. Or thank myself for that matter. Tha would make me a little nuts dont you think? :rolleyes:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users