0

我是 PHP 新手。我正在尝试通过 php 脚本防止重复。我使用 wamp 服务器。这是代码,

$query1="select COUNT(email) from customer_info where email=$eml";
$res1=mysqli_query($db_Con,$query1);
$row=mysqli_fetch_assoc($res1);

我想知道这里的 $row 是否有计数值。即如果 xyz@abc.com 在“customer_info”中已经存在(一次出现),$row 的值是否为“1”?

究竟应该传递给 mysqli_fetch_assoc() 什么?我收到警告说它需要 "mysqli_result" ,而不是布尔值。

PS:我不想将表格中的电子邮件列设为唯一。

谢谢!

4

1 回答 1

0

试试这个解决方案

$query = "SELECT COUNT(email) AS res FROM customer_info WHERE email = $eml"; // res is a alias... can be any unreserved word
$st = mysqli_query($db_con, $query);
$row = mysqli_fetch_object($st); //mysqli_fetch_object bind the resultset as object into the variable as described here http://php.net/mysqli_fetch_object

// $row->res is a object with property "res" from your query
if($row->res > 0)
{
  //has an e-mail
}
else
{
  ///
}
于 2012-12-06T19:07:11.477 回答