【问题标题】:The config reports the $count error message配置报告 $count 错误信息
【发布时间】:2014-11-21 20:37:17
【问题描述】:

当我提交密码和用户名时,php的配置文件是空白的。为了知道问题是什么,我回显了所有错误消息。在 $count 查询中,我写了一条错误消息,即“电子邮件和密码不匹配”。

if($count===1)
   {
    $_SESSION['logged_in'] = true;
    header("location:index.php");
    exit; 
   }
else
   {
    echo "the emailand password doesn't match.";
    exit;
   }

当我重新提交登录表单时,它会打印出回显“用户名和密码不匹配”。我在表格中检查了密码和用户名是否正确。

这是完整的脚本:

error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", true);
error_reporting(-1);
ini_set('display_errors', 'On');

$mysqli = new mysqli("com", "ih", "th", "rcser");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
  }

$myemail= $_POST['myemail']; 
$mypassword= $_POST['mypassword'];

$sql= "SELECT * FROM user WHERE myemail = ? and mypassword = ?";
/* create a prepared statement */
if ($stmt = $mysqli->prepare($sql)) {

/* bind parameters for markers */
$stmt->bind_param("ss", $myemail, $mypassword);

/* execute query */
$stmt->execute();

/* count */
$count = $stmt->num_rows;

/* close statement */
$stmt->close();
}

/* close connection */
$mysqli->close();

if($count===1){
$_SESSION['logged_in'] = true;
header("location:index.php");
exit; 
}
else
{
echo "the email and password doesn't match.";
exit;
}

ob_end_flush();
?>

【问题讨论】:

  • 我在任何地方都看不到 $username 设置。另外,不应该算 if($count == 1) not ===
  • 应该怎样设置$username?我已经编辑了这个问题。好吧,如果 === 是问题,我会检查它。
  • == vs. === 如果类型匹配应该不是问题
  • 您设置的 $username 不存在。你需要用一些东西来设置它,也许是电子邮件。你在检查什么。不过很容易绕过那个登录脚本。
  • 很遗憾,这不是问题。

标签: php mysql session mysqli


【解决方案1】:

也许错误是在查询中:

$sql = "SELECT * FROM user WHERE myemail=".$_POST['myemail']." AND mypassword=".$_POST['mypassword']."";

或者

$sql = "SELECT * FROM user WHERE myemail=".$myemail." AND mypassword=".$mypassword."";

试试看

【讨论】:

  • 我没有试过你给出的解决方案,但是这个语句怎么样:$stmt->bind_param("ss", $myemail, $mypassword);我想它已经解释了查询?
猜你喜欢
  • 2015-05-19
  • 1970-01-01
  • 2022-06-18
  • 1970-01-01
  • 2016-08-13
  • 1970-01-01
  • 2020-07-05
  • 2011-11-14
  • 1970-01-01
相关资源
最近更新 更多