我似乎不知道如何更新我的上次登录时间 [英] I can't seem figure out how to update my last inlog time

查看:37
本文介绍了我似乎不知道如何更新我的上次登录时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to make an last activity function for an website. but i can't get it to work. I hope you guys can help me out here.

这是我的脚本:

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
                    }
                }
            ?>

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

this is an print screen of my database table:

http://i.stack.imgur.com/xDMGA.png

提前致谢!

推荐答案

在您的查询中:

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

尝试删除 date_last_inlog 周围的引号或将它们更改为反引号:

Try removing the quotes around date_last_inlog or changing them to backticks:

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

另外,不要使用mysql_* 函数,而是使用mysqliPDO.您的代码容易受到 SQL 注入攻击.

Also, don't use the mysql_* functions, use mysqli or PDO instead. Your code is vulnerable to SQL Injection.

这篇关于我似乎不知道如何更新我的上次登录时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆