dongxie3352 2014-10-17 21:16
浏览 32
已采纳

mysql准备好的语句不起作用

I'm new to MySQL. I created a login page that will run PHP to query the database.

I want to make a prepared statement to prevent SQL injection but it is not working. $result gives me 0.

cgi-bin/welcome.php

<?php
$email= $_POST["email"];
$pwd = $_POST["password"];

$dbh=mysqli_connect("localhost",
"zzengnin",<password>,"zzengnin_wheel")
or die ('Database is not able to connect');

$qry= "SELECT email FROM Info WHERE email=? AND pw=?";

if ($stmt = mysqli_prepare($link, $qry)) {
    mysqli_stmt_bind_param($stmt, "ss", $email, $pwd);
    mysqli_stmt_execute($stmt);

    mysqli_stmt_bind_result($stmt, $result);
    mysqli_stmt_fetch($stmt);
    printf("result email  is %s
", $result);
}


if(mysqli_num_rows($result)>0)
{
    echo "Welcome! '$email', you are officially logged in! ";
}
else{
    echo "Your Email or Password is WRONG!!!!";

    echo $result + " result";
}
mysqli_stmt_close($stmt);
mysqli_close($dbh);
?>

This is the form login.php

<!DOCTYPE html>
<head><title>Wheel Sharing</title>
<link rel = "stylesheet" type = "text/css" href = "CSS/style.css">
</head>
<body>
<h1>Log in</h1>

<form action="cgi-bin/welcome.php" method="post">
Email:  <input name="email" type="text" size="20"/>
<br/>
Password: <input name="password" type="password" >
<br/>
<input type="submit" value="Login"/> <input type="reset" value="Reset"/>

</form>

</body>
</html>

All help appreciated:)

  • 写回答

1条回答 默认 最新

  • doupin2013 2014-10-17 21:34
    关注

    Change this:

    mysqli_stmt_execute($stmt); 
    

    To this:

    $result = mysqli_stmt_execute($stmt);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图