How can I update table once and echo "Already updated" if table update is done before and should redirect to login if already updated. Here is my update query
<?php
$dbhost="xxxx";
$dbusr="xxxx";
$dbpass="xxxx";
$database="xxxxx";
mysql_connect($dbhost,$dbusr,$dbpass, $database);
mysql_select_db($database) or die("databse not connected");
$num = rand(98564654, 415231564);
If(isset($_POST['login'])){
$Pin=$_GET['pin'];
$ID =$_POST['ID'];
$date=date('Y-m-d H:i:s');
if($Pin!=''){
mysql_query("UPDATE pin SET appid ='$num', status='Activated' WHERE Pin= '$Pin'")
or die(mysql_error());
mysql_query("INSERT IGNORE INTO pinlog (TableName,pin,id,TIME_UPDATED) VALUES('Pin','$Pin','$num','$date')")
or die(mysql_error());
header("location:applicantlogin.php");
}
}
?>
Please Help
Perhaps this helps:
First, set PIN activated only when its not activated:
UPDATE pin SET appid ='$num', status='Activated'
WHERE Pin= '$Pin' AND status <> 'Activated'
Then, find out how many rows were affected (there's a function for that). If 0 then already activated and bail out. Check your indexes as well.