PHP& MySQL Bug

时间:2014-03-23 07:10:49

标签: php mysql debugging

接下来的代码是我试图建立一个检查用户名(电子邮件)&的登录页面的做法。密码与现有帐户。我有一个提交信息的登录页面,但一旦进入第二页进行处理,它就不会给我一个成功的登录。现在我已经注释掉了部分代码,并认为bug存在于while循环的某个地方。

代码尝试从表单中获取POSTed数据,并将其与名为"注册"的数据库进行比较。与表'帐户'。表中当前有4行数据,其中包含用户名1,12,123和1234.所有密码均为2.无论我的输入是什么,它都给出了我设置的相同错误 - "系统中没有此类登录。请再试一次。" "尝试失败。"

<html>
<link rel="stylesheet" type="text/css" href="format.css" />

<?php

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

//Change localhost to match yours
$connect = mysqli_connect("localhost:8889", "root", "root", "registered");


$sql= "SELECT * FROM `accounts` WHERE email ='$email'";
$result = mysqli_query($connect, $sql);


while($row = mysqli_fetch_array($result))
  {
    if ($password == $row["password"] ){
        echo "successfull login";
        echo "<script>window.location.href='session.php'</script>";
    }
}

if(mysqli_affected_rows($connect)==0)
{
echo "<p> no such login in the system. please try again. </p>";
}
else{
echo "successfully logged into system.";
echo "<script>window.location.href='session.php'</script>";
}

mysqli_close($connect);

echo "<p> Failed attempt. </p>"
?>
</html>

**好的,我修复了$ result = mysql ... - &gt; $ result = mysqli .... 但我仍然遇到同样的错误。

**我改变了mysql_affected_rows() - &gt; mysql_affected_rows($连接) 仍然得到那些错误

** mysql_close - &gt; mysqli_close($连接); 啊仍然得到错误

感谢您的帮助。希望这最终会成功。

2 个答案:

答案 0 :(得分:0)

$result = mysql_query($connect, $sql);

应该是

$result = mysqli_query($connect, $sql);

坚持还有更多

if(mysql_affected_rows()==0)

应该是

mysqli_affected_rows($connect)

mysql_close($con);

应该是

mysqli_close($connect);

答案 1 :(得分:0)

mysql_affected_rows()

应该是:

mysqli_affected_rows($connect)