Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Feb 2007
    Posts
    219
    Thanks
    25
    Thanked 1 Time in 1 Post

    dupicate entry ?

    The idea is to check whether the last record which was added to the db is the same as a variable. So I store the last record into a new variable called $laatste in my php.

    But when I try to add the new record, I get an error.. namely:

    Code:
    laatste:testingQUERY ERROR! Query is INSERT INTO find (searched, datum) values ('test1','2012-10-19 10:14:51')
    Error is Duplicate entry '127' for key 'PRIMARY'
    Code:
    				$sql = "SELECT * FROM find ORDER BY datum DESC LIMIT 1;";
    				$resultzoek = mysql_query($sql); if (!$resultzoek) { die("QUERY ERROR!  Query is $sql<br />Error is ".mysql_error());}
    
    				while($row = mysql_fetch_array($resultzoek))
    				{
    				$laatste=$row['searched'];
    				}
    				
    				echo "last:". $laatste;
    
    //if $laatste differs from $keywords, add a new record to the db				
    				
    				if( isset( $_GET['keywords'] )){
    				$keywords=$_GET['keywords'];
    				$today = date("Y-m-d H:i:s");  
                    $sql = "INSERT INTO find (searched, datum) values ('".mysql_real_escape_string($keywords)."','$today')";
    				$result = mysql_query($sql); if (!$result) { die("QUERY ERROR!  Query is $sql<br />Error is ".mysql_error());}
    				}
    The coding runs fine without the retrieve of the last record, so I don't understand what's going on here, and how I could alter my coding so that it would work.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Error is Duplicate entry '127' for key 'PRIMARY'
    This error likely means you are using an auto increment on a TINYINT column type. You have reached 127 rows inserted (even if you have deleted some) so the next row is trying to insert a value of 127 which is the maximum value for TINYINT.

    Change the column type to SMALLINT or INT and you should no longer run into the problem.

    It has nothing to do with the string you are trying to insert.

  • Users who have thanked guelphdad for this post:

    docock (10-19-2012)

  • #3
    Regular Coder
    Join Date
    Feb 2007
    Posts
    219
    Thanks
    25
    Thanked 1 Time in 1 Post
    Thank you very much, I wouldn't have figured this out myself!

  • #4
    New Coder
    Join Date
    Oct 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Can anyone suggest more information on this duplicate entry..
    How can i identify either it is genuine or not. Is there and another tool to identify the target.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    If MySQL says it's a duplicate entry, it *IS* a duplicate entry. Genuine. Guaranteed.

    Why would you doubt MySQL?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •