So, my table has a bunch of codes in it and I don't want more than one of the same code in the table so I have it as "UNIQUE." But, at the same time, I want them to be able to bump their code once every hour.
function some_more_custom_content() {
$output="<BR>";
ob_start();
if ($_REQUEST['code'] != "") {
$code = $_REQUEST['code'];
$query="INSERT INTO `fc` (`code`,`datetime`) values ('" . mysql_real_escape_string($code) . "', now())";
$result=mysql_query($query) or die(mysql_error());
$seconds = time() - strtotime($fetch_array["datetime"]);
if($sql){
echo("Intserted " . htmlentities($code) ." into the top.");
}else{
if ($seconds < 60*60) {
echo ("The code " . htmlentities($code) ." was updated less than an hour ago.");
} else {
$query="DELETE FROM `fc` (`code`,`datetime`) values ('" . mysql_real_escape_string($code) . "', now())";
echo ("Inserted " . htmlentities($code) ." into the top.");
}
}}
Now, I tried to get it so that when the code works it submits the code as normal, which I think works.
Now, if it gets a code that is already there I get the duplicate error "Duplicate entry 'Bob' for key 1"
But, I just want it to delete the old query that it found and to resubmit if it's been more than one hour since last submission.
Any ideas what I am doing wrong?