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.