开发者

How to simply update specific timestamps in mysql?

I'm having a hard time finding an example of just making a simple update function to update the time in my timestamp column in any row that contains my $username variable. Any ideas how I could make this work?

class updateUserData {

    public function __construct() {
        mysql_connect开发者_高级运维("mysql.mymysql.com", "admin", "password");
        mysql_select_db("my_db");
    }

    function userUpdate($username) {
        return mysql_query("UPDATE mytable WHERE username = '$username' SET timestamp = 'NOW()'");
    }
}


Reverse the order of your update. See MySQL UPDATE Syntax

UPDATE   mytable
SET      timestamp = NOW()
WHERE    username = 'username'

Also, NOW() is a function, so don't enclose it in quotes.


"UPDATE mytable SET timestamp = NOW() WHERE username = '$username' "

skip '' around NOW() and provide correct order of UPDATE SET WHERE

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜