douhui5529 2015-01-22 17:32 采纳率: 100%
浏览 28
已采纳

登录php脚本

I have here a login script.I removed from it the database username/password to post it on stack.My problem is that it tells me everytime I write a username and a password(even when they are correct) that the password and username are invalid.I obviously used select *from ........ and then put a variable $rows to count the affected rows,but it's value is 0 everytime and I am not able to log in.

<h1>Log in</h1>
<form action="" method="post">

    Username:<input type="text" name="username" placeholder="username" value=""/> <br />

    Password:<input type="password" name="password" placeholder="*******" value=""/> <br />

    <input type="submit" name="submit" value="Log In" />
             <br />


</form>





    <?php

    $error=''; 
    if (isset($_POST['submit'])) {
    if (empty($_POST['username']) || empty($_POST['password'])) {
    $error = "Username or Password is empty";
    echo $error;
    }
    else
    {

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

    $connection = mysql_connect("mysql.hostinger.ro", "_patr0", "  ");

    $username = stripslashes($username);
    $password = stripslashes($password);
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);

    $db = mysql_select_db("_ppl", $connection);



    $query = mysql_query("select * from people where pw='$password' AND username='$username'", $connection);


    $rows=mysql_num_rows($query);

    if ($rows==1) {


    /*$_SESSION['login_user']=$username;*/ // Initializing Session


    echo 'You are logged in';
    } else {
    $error = "Username or Password is invalid";
    }
    echo $error;
    mysql_close($connection); // Closing Connection
    }
    }
    ?>
  • 写回答

2条回答 默认 最新

  • doukong9316 2015-01-22 17:46
    关注

    Yes I am sure.David I stored the passwords using aes_encrypt('$password','text')

    This could be your problem, when you are running your mysql query here you are trying to match a plain text password from the user input, but you store them as encrypted strings. You need to encrypt the password in your SQL query.

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

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据