Jump to content

Archived

This topic is now archived and is closed to further replies.

davina

error message:Duplicate entry '' for key 1

Recommended Posts

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>

 

Share this post


Link to post
Share on other sites

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> </td>

<td> </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> </td>

<td> </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"> </p>

</body>

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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:

Share this post


Link to post
Share on other sites

×

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.