Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-19-2012, 03:29 PM   PM User | #1
docock
Regular Coder

 
Join Date: Feb 2007
Posts: 197
Thanks: 21
Thanked 1 Time in 1 Post
docock is an unknown quantity at this point
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.
docock is offline   Reply With Quote
Old 10-19-2012, 06:05 PM   PM User | #2
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
Quote:
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.
guelphdad is offline   Reply With Quote
Users who have thanked guelphdad for this post:
docock (10-19-2012)
Old 10-19-2012, 06:12 PM   PM User | #3
docock
Regular Coder

 
Join Date: Feb 2007
Posts: 197
Thanks: 21
Thanked 1 Time in 1 Post
docock is an unknown quantity at this point
Thank you very much, I wouldn't have figured this out myself!
docock is offline   Reply With Quote
Old 10-31-2012, 01:26 PM   PM User | #4
crewson548
New Coder

 
Join Date: Oct 2012
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
crewson548 is an unknown quantity at this point
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.
crewson548 is offline   Reply With Quote
Old 10-31-2012, 04:41 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,565
Thanks: 62
Thanked 4,057 Times in 4,026 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:30 PM.


Advertisement
Log in to turn off these ads.