donglang6656 2013-06-15 23:04
浏览 29

无法登录我的网站工作

I updated my code and used mysqli this time I don't get any more errors But it doesnt let me log in now.

<?php
$host = 'my host';
$user = 'me';
$PW = 'my password';
$dB = 'login';
$table = 'members';
$field = 'username';    
/* Create a new mysqli object with database connection parameters */
$mysqli = new mysqli($host, $user, $PW, $dB);
if(mysqli_connect_errno()) {
    echo "Connection Failed: " . mysqli_connect_errno();
    exit();
}    
//Grab User submitted information
$name = $_POST['username']; //login name
$pass = $_POST['password'];  //login password    
/* Create a prepared statement */
if($stmt = $mysqli -> prepare("SELECT f_name FROM $table WHERE $field=?
AND password=?")) {
    /* Bind parameters
    s - string, b - blob, i - int, etc */
    $stmt -> bind_param("ss", $name, $pass);
    /* Execute it */
    $stmt -> execute();        
    /* Bind results */

    $stmt -> bind_result($result);

    /* Fetch the value */

    $stmt -> fetch();

    if ($result == NULL) {
        echo "That combo of username and password is wrong!";
    }
    else{
        echo "Hello " . $result;
    }
    /* Close statement */
    $stmt -> close();
}
/* Close connection */
$mysqli -> close(); 
?>

I think it works now but even when I enter the correct ID & PW it says I didn't. I don't know why it would do this.

  • 写回答

3条回答 默认 最新

  • doujiekeyan0622 2013-06-15 23:11
    关注

    your problem is

     $_POST["usersname"]
    

    is not defined.

    when you use the $name in your query use this mysql_real_escape_string($name) .

    if this is your code , its catastroph for sql injections . you should change to mysqli or PDO

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向