如果完成则阻止 MySQL 更新
我的 MySQL 更新有问题。下面的代码可以正常工作,但我想阻止其他人再次尝试在“状态”字段中输入数据。
我该如何编写命令呢?
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;
}
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 "status" 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以做到这一点:
向表中添加一个字段 -
IS_UPDATED
- 以维护某种默认为 FALSE 的标志。然后,在更新status
字段的查询中,还将IS_UPDATED
设置为 TRUE。另外,在更新查询中,将此条件添加到 where 子句 -IS_UPDATED = FALSE
。这意味着status
列仅在尚未更新时才会更新。如果字段
upl_time
本来是NULL或空,并且只在上面的查询中更新,那么当status
列更新时,我想你也可以使用此列而不是添加新列。但这是您更了解的。我不确定您的应用程序更新查询的来源是什么。但如果可能的话,您也可以考虑向您的应用程序添加逻辑以完全禁用更新。
我更喜欢方法1。
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.