0

I am having trouble getting this to work, I need to update a table in my database, changing one of the fields for all records that fall in between two dates and have a certain user name.

The date values are being passed to a script from a form.

What I have:

mysql_query("
    UPDATE data 
    SET status='Submitted' 
    WHERE (user_name = '$current_user->user_login') 
    AND labor_date >= '$_POST[start]' 
    AND labor_date <= '$_POST[end]'")

Any ideas what I am doing wrong? Thanks for any help!

L

4

1 回答 1

1

确保您的日期采用以下格式:

yyyy-mm-dd

您还可以检查 mysql_affected_rows() 以查看查询是否成功运行但找不到符合条件的行。

您可能还希望将字符串构建为变量,例如 $sql = "...";

这将允许您将其回显以进行调试。

*您确实意识到 mysql_ 是一个已弃用的库,并且很快将完全从 PHP 中删除?此时您应该使用 mysqli 或 PDO。*

哦,是的,关于用键插值数组的一个小技巧:

AND labor_date >= '{$_POST['start']}' 
于 2013-11-07T21:49:14.670 回答