RE: Duplicate keys...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	Thanks once again.  I finally figured this out late yesterday.  I
have no idea as to why whoever wrote this calendar to begin with did it this
way.  On suggestion I have for anyone looking at a calendar system to use or
modify is to absolutely NOT use phpCommunityCalendar.  This is a very poorly
coded piece of software, and if I as a relative PHP newbie know this, it is
really bad.

-----Original Message-----
From: John W. Holmes [mailto:holmes072000@charter.net]
Sent: Wednesday, January 15, 2003 10:07 PM
To: NIPP, SCOTT V (SBCSI); php-db@lists.php.net
Subject: RE:  Duplicate keys...


> 	OK, I cannot figure out why I keep getting errors about
"Duplicate
> entry for key 1".  Someone please come to my rescue here as this is
truly
> kicking my but.

You have a key or unique column in your table that you're trying to
insert a duplicate value into.
 
> if ($dateDiff == 2) {
> 	mysql("$DBName","INSERT INTO phpCalendar_Details VALUES (
> 	'$said','Comp day for weekend
> On-Call','','','','','','','','','',2,'$CalendarDetailsID')") or
> die(mysql_error());
> 
> 	mysql("$DBName","UPDATE Balances SET CompEarned=CompEarned+8,
> CompTaken=CompTaken+8 WHERE said='$said'") or die(mysql_error());
> 	$result = mysql("$DBName","SELECT LAST_INSERT_ID() FROM
> phpCalendar_Details") or die(mysql_error());
> 		while ($row = mysql_fetch_row($result)) {
> 		$CalendarDetailsID = $row[0];
> 		}
> 	mysql("$DBName","INSERT INTO Log VALUES(
> 	'$entryid','$said','Comp',DATE_ADD('$StopDate',INTERVAL 1
> DAY),'Y','','Awarded for weekend On-Call','8','$CalendarDetailsID')")
or
> die(mysql_error());
> 
> 	mysql("$DBName","INSERT INTO phpCalendar_Daily VALUES(
> 	DATE_ADD('$StopDate',INTERVAL 1
DAY),'',1,2,'$CalendarDetailsID')")
> or die(mysql_error());
> }
> 
> if ($dateDiff < 0) {
> commonHeader($glbl_SiteTitle);
> echo "<center><font color=\"red\"><b>Your END DATE COMES BEFORE YOUR
START
> DATE. Please complete the form below.</b></font></center><p>\n\n";
> 
> } elseif ($Stop != 1) {
> 
> if ($CalendarDetailsID) {
> 	$CalendarDetailsID = $CalendarDetailsID + 1;
> } else {
> 	$result = mysql("$DBName","SELECT LAST_INSERT_ID() FROM
> phpCalendar_Details") or die(mysql_error());
> 	while ($row = mysql_fetch_row($result)) {
> 	$CalendarDetailsID = $row[0];
> 	}
> }
> 
> mysql("$DBName","INSERT INTO phpCalendar_Details VALUES (
> '$said','On-Call for $StartDate to
> $StopDate','','','','','','','','','',1,'$CalendarDetailsID')") or
> die(mysql_error());
> 
> mysql("$DBName","INSERT INTO phpCalendar_Daily VALUES(
> '$StartDate','$StopDate','1','1','$CalendarDetailsID')") or
> die(mysql_error());
> 
> 	This is the only place in the script that is attempting to enter
> data into the CalendarDetailsID field.  This is the auto_increment
field
> that is having problems, I think.  The other strange part of this is
that
> thedata in the auto_increment field has two separate ranges (10 - 40
with
> gaps, and 70 - 78 with gaps).  I have been doing a lot of adding and
> removing of data to test during development, but I thought an
> auto_increment
> field would still track and deal with this correctly.

If you're trying to insert a number into an auto_increment field that's
already there, you'll get this error. You should always insert a NULL
value into an auto_increment column so MySQL will handle giving it the
number itself.

Also, don't worry about the gaps. They are irrelevant. If the gaps
matter to your program, then you are coding incorrectly. The
auto_increment column is there _only_ to provide a unique identifier for
each row and nothing else. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux