0

我正在尝试为网站制作最后一个活动功能。但我无法让它工作。我希望你们能在这里帮助我。

这是我的查询:

$last_activity_query = "UPDATE users_table SET user_name  = '$user_name' WHERE 'date_last_inlog' = NOW()";

$result_update =  mysql_query($last_activity_query);

$last_activity_update = mysql_fetch_array($result_update);

这是我的数据库表的打印屏幕:

在此处输入图像描述

我想将此更新存储在最后一行。

提前致谢!

我现在更改了我的脚本,但它仍然没有更改我的数据库表中的任何内容。

这是变化:

if (isset($_REQUEST['inlog_submit'])){//checks if form is submitted


                    $user_name = $_REQUEST['username_input'];//request username from inlog_form
                    $password = $crypt;//gets enqrypted pass
                    //$tbl_name="user_table"; // Table name
                    $query = "SELECT * FROM users_table WHERE user_name= '$user_name' AND password='$password'";//query stored in var
                    $last_activity_query = "UPDATE users_table SET 'date_last_inlog' = NOW() WHERE user_name  = '$user_name'";
                    $result = mysql_query($query);//var with result of query
                    $result_update =  mysql_query($last_activity_query);

                    if ($user_name = mysql_fetch_array($result)){//checks inlog data from form with the $result query
                        $_SESSION['user_name'] = $user_name[user_name];//creates session with username
                        $_SESSION['password'] = $password[password];//creates session with password
                        $last_activity_update = mysql_fetch_array($result_update);
                        header ('Location: admin.php');//when login is correct redirect to specified page
                    }else{
                        $error_inlog = 10;//when inlog data is incorrect this error will show
                    }
                }
            ?>
4

2 回答 2

2

您的 SQL 查询顺序错误。

$last_activity_query = "UPDATE users_table SET 'date_last_inlog' = NOW() WHERE user_name  = '$user_name'";
于 2013-07-17T17:54:24.430 回答
1

你的逻辑不正确。用这个:-

"UPDATE users_table SET 'date_last_inlog' = NOW() WHERE user_name  = '$user_name'";

你正在使用这个: -

UPDATE users_table SET user_name  = '$user_name' WHERE 'date_last_inlog' = NOW()

您正在尝试更新user_namedate_last_inlog值等于当前时间的列,这在逻辑上是不正确的。

于 2013-07-17T17:55:45.597 回答