Php 登录表单上返回0的行数

Php 登录表单上返回0的行数,php,ajax,mysqli,mysql-num-rows,Php,Ajax,Mysqli,Mysql Num Rows,我知道这已经讨论过了,但这个问题有点令人困惑。我正在使用mysqli编写的语句,但我也尝试使用原始查询。num_rows总是0,我不知道为什么。因此,登录表单失败。 下面是php代码: <?php include("config.php"); session_start(); if(isset($_POST["userLogin"])){ $email = ($_POST["userEmail"]); $password =($_POST["userPassword"]); $stmt

我知道这已经讨论过了,但这个问题有点令人困惑。我正在使用mysqli编写的语句,但我也尝试使用原始查询。num_rows总是0,我不知道为什么。因此,登录表单失败。 下面是php代码:

<?php
include("config.php");

session_start();
if(isset($_POST["userLogin"])){
$email = ($_POST["userEmail"]);
$password =($_POST["userPassword"]);
$stmt = $con->prepare("SELECT * FROM customers WHERE 
'customer_email'=? AND 'customer_password' =?");
$stmt->bind_param("ss", $email, $password);
$stmt->execute();

$stmt->store_result();
$stmt->bind_result($email, $password);
if($stmt->affected_rows == 1){
$stmt->fetch_assoc();
$_SESSION["user"] = $row["customer_id"];
$_SESSION["email"] = $row["customer_email"];

echo "logged in";

} else {
echo "Email / password combination incorrect";
}
}
?> 
下面是HTML

<label for="email">E-mail Address</label>
<input type ="email" class ="form-control" id="email" required/>
<label for="email">Password</label>
<input type ="password" class ="form-control" id="password" required/>
<p><br/></p>
<a href="#" style="color:white; list-style:none;">Forgotten 
Password</a><input type="submit" class="btn btn-success" 
style="float:right;" id="login" value="Login">

注册工作正常,没有其他问题。我之前让mysql num_行返回0,存储结果修复了这个问题。然而,这一次太复杂了。我已经试着调试了好几个小时,什么也没试过。非常感谢您的帮助。

偶然发现了这个老问题。您似乎在字段/列名周围使用引号(')。据我所知,而且文档也同意,mySQL不支持这一点。如果出现以下情况,则必须使用一个:

  • 无,示例:从表1中选择字段1
  • 背景标记,例如:从表1中选择'field1'
  • 双引号,示例:从表1中选择“field1”
最后一个选项仅适用于启用ANSI_引号的情况

现在我还没有尝试过您的代码,但是使用引号可以使您的查询比较两个字符串,而不是字段/列与字符串。你的问题

“客户电子邮件”=


文字含义:将文本customer_email与绑定参数的值进行比较。除非表单中输入的用户名/电子邮件是customer_email,否则它将永远不会匹配。密码也是一样。

我尝试用num rows替换受影响的行,也没有提取。同样的问题。Mysql认为我有0行,尽管我有很多!我不知道如何解决这个问题,但这是非常令人不安的。我已经试了24个多小时了。有什么建议吗?您在哪里使用
num_rows
?我看到
受影响的\u行
,它根据返回受INSERT、UPDATE或DELETE查询影响的行数。你做了一个
选择
我尝试了num行和受影响的行,它们都返回0。我将受影响的行用于此web应用程序的搜索功能,效果很好。jquery代码有问题。我试过使用php,效果很好。我能了解一下我在ajax上犯了什么错误吗?
<label for="email">E-mail Address</label>
<input type ="email" class ="form-control" id="email" required/>
<label for="email">Password</label>
<input type ="password" class ="form-control" id="password" required/>
<p><br/></p>
<a href="#" style="color:white; list-style:none;">Forgotten 
Password</a><input type="submit" class="btn btn-success" 
style="float:right;" id="login" value="Login">
INSERT INTO `customers` (`customer_id`, `customer_name`, 
`customer_email`, `customer_pass`, `customer_country`, 
`customer_city`, `customer_address`, `customer_zipcode`)