当用户通过php

时间:2017-02-04 12:28:21

标签: php mysql html5

<?php
    session_start();
    require_once('dbconfig/config.php');
    //phpinfo();
?>

<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body style="background-color:#bdc3c7">
    <div id="main-wrapper">
    <center><h2>Login Form</h2></center>
            <div class="imgcontainer">
                <img src="imgs/avatar.png" alt="Avatar" class="avatar">
            </div>
        <form action="index.php" method="post">

            <div class="inner_container">
                <label><b>Username</b></label>
                <input type="text" placeholder="Enter Username" name="username" required>
                <label><b>Password</b></label>
                <input type="password" placeholder="Enter Password" name="password" required>
                <button class="login_button" name="login" type="submit">Login</button>
                <a href="register.php"><button type="button" class="register_btn">Register</button></a>
            </div>
        </form>

        <?php
            if(isset($_POST['login']))
            {
                @$username=$_POST['username'];
                @$password=$_POST['password'];
                                @$date=$_POST[date('Y-m-d')];
                $query = "select * from userinfotbl where username='$username' and password='$password' ";
                                $query1="insert into userinfotbl values('$date')";
                //echo $query;
                $query_run = mysqli_query($con,$query);
                                $query_run1 = mysqli_query($con,query1);
                //echo mysql_num_rows($query_run);
                if($query_run)
                {
                    if(mysqli_num_rows($query_run)>0)
                    {
                    $row = mysqli_fetch_array($query_run,MYSQLI_ASSOC);

                    $_SESSION['username'] = $username;
                    $_SESSION['password'] = $password;

                    header( "Location: homepage1.php");
                    }
                    else
                    {
                        echo '<script type="text/javascript">alert("No such User exists. Invalid Credentials")</script>';
                    }
                }
                else
                {
                    echo '<script type="text/javascript">alert("Database Error")</script>';
                }
            }
            else
            {
            }
        ?>

    </div>
</body>
</html>

我的数据库中的日期字段正在填充0000-00-00。我需要在用户点击登录按钮时插入该字段与系统日期。我无法检测到问题。我有一个变量$ date指定功能日期(&#39; Ym-d&#39;)。

3 个答案:

答案 0 :(得分:0)

替换

 function updateOrDeleteEntitlements(context) {
    var role = $('#selectedRole').val();
    var ent = $(context).data('entid');
    var binMe = '';

     $.ajax({
      url: 'ajax/update_delete_entitlements.php',
      type: 'post',
      data: {'role': $role, 'ent': ent, 'delete': $binMe},
      success: function(data) {
        console.log(data);
      }
    }); 
 }

@$date=$_POST[date('Y-m-d')];

答案 1 :(得分:0)

取代@$date=$_POST[date('Y-m-d')]使用@$date = date('Y-m-d H:i:s'); 在Mysql数据库字段中选择数据类型DATETIME。

<?php
    if(isset($_POST['login']))
    {
      @$username=$_POST['username'];
      @$password=$_POST['password'];

      //@$date=$_POST[date('Y-m-d')];
      @$date = date('Y-m-d H:i:s');


    $query = "select * from userinfotbl where username='$username' and password='$password' ";
                    $query1="insert into userinfotbl values('$date')";
    //echo $query;
    $query_run = mysqli_query($con,$query);
                    $query_run1 = mysqli_query($con,query1);
    //echo mysql_num_rows($query_run);
    if($query_run)
    {
        if(mysqli_num_rows($query_run)>0)
        {
        $row = mysqli_fetch_array($query_run,MYSQLI_ASSOC);

        $_SESSION['username'] = $username;
        $_SESSION['password'] = $password;

        header( "Location: homepage1.php");
        }
        else
        {
            echo '<script type="text/javascript">alert("No such User exists. Invalid Credentials")</script>';
        }
    }
    else
    {
        echo '<script type="text/javascript">alert("Database Error")</script>';
    }
}

?>

答案 2 :(得分:0)

您好,您只需要将date数据类型更改为timestamp并设置默认CURRENT_TIMESTAMP。 这将自动添加日期值列,您无需在查询中提供日期。