Block MySQL UPDATE if is done
I have a Problem with MySQL update. The code below is working but i want to block that others try to enter Data at Field "stat开发者_JAVA百科us" again.
How can i write the command for that?
if(isset($_GET['up']))
{
if(strlen($_GET['up'])==71)
{
db_conn();
$raw = explode(":",$_GET['up']);
$sql = "UPDATE ".$database_table." SET status='".$raw[1]."',upl_time='".time()."' WHERE hash='".$raw[0]."' LIMIT 1";
if(mysql_query($sql))
{
print "ACK";
}
else
print "NACK";
}
exit;
}
There are a couple of ways to do so:
Add a field -
IS_UPDATED
- to your table to maintain some sort of a flag that defaults to FALSE. Then in your query that updates thestatus
field, also setIS_UPDATED
to TRUE. Also, in the update query, add this condition to the where clause -IS_UPDATED = FALSE
. This will mean that thestatus
column will only update if it has not already been updated.If the field
upl_time
is originally NULL or empty, and is only updated in the above query, when thestatus
column is updated, I think you can as well use this column instead of adding a new one. But this is better known by you.I'm not sure what's the origin of the update query from your application. But if possible, you might also consider adding logic to your application to disable the UPDATE altogether.
I'd prefer approach 1.
精彩评论