dsfjk44656 2018-10-11 05:28
浏览 66
已采纳

如何在mysql PHP中插入用户登录日期时间[关闭]

I am beginner in PHP and I would like to store the users login time in another table called LoginHistory, I don't know how to write a query. Can u help me on that please?

<?php
include_once "conn.php";

if (!isset($_SESSION)) {
session_start();
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (empty($_POST["mobile_no"]) && empty($_POST["log_password"])) {
echo '<script>alert("Both Fields are required") </script>';
}
$sql = "select * from Users where Mobile='" . $_POST['mobile_no'] . "' and 
Password='" . md5($_POST['log_password']) . "'";
if ($result = mysqli_query($conn, $sql)) {
$rowcount = mysqli_num_rows($result);
}
if ($rowcount > 0) {
$row = $result->fetch_assoc();
$_SESSION["userId"] = $row['Id'];
$_SESSION["ConstituencyId"] = $row['ConstituencyId'];
$succmsg = "Login Success";
header("location:user-login-welcome.php");
} else {
$errmsg = "Invalid Username / Password..";
}
}
?>
  • 写回答

3条回答 默认 最新

  • duanaixuan7385 2018-10-11 05:38
    关注

    In your login success condition just add your insert code to insert date in another table

    if ($rowcount > 0) {
        $row = $result->fetch_assoc();
        $_SESSION["userId"] = $row['Id'];
        $_SESSION["ConstituencyId"] = $row['ConstituencyId'];
        $succmsg = "Login Success";
       // Add your login time insert code like below
        $date = date('Y-m-d H:i:s');
        mysql_query("INSERT INTO `table` (`dateposted`) VALUES ('$date')");
        header("location:user-login-welcome.php");
    }
    

    You can change datetime, Check the date time manual of PHP

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 MATLAB四叉树处理长方形tif文件
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了