开发者

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:

  1. 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 the status field, also set IS_UPDATED to TRUE. Also, in the update query, add this condition to the where clause - IS_UPDATED = FALSE. This will mean that the status column will only update if it has not already been updated.

  2. If the field upl_time is originally NULL or empty, and is only updated in the above query, when the status 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.

  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜