我试过检查sql数据库中的存在行,但它总是返回此错误。我试过研究他们给了一些解决方案,但没有工作。请帮忙!!
$usersexist = mysqli_query($con, "SELECT phone FROM usersacc WHERE phone = '$pho'");
$count= mysql_num_rows($usersexist) or die(mysql_error());
if($count > 0)
{
$result_data = array(
'ResultArray' => 'Exist',
);
}
else
{
mysqli_query($con,"INSERT INTO usersacc
(phone, password) VALUES('$pho', '$pass')");
#Build the result array (Assign keys to the values)
$result_data = array(
'ResultArray' => 'success',
);
}
#Output the JSON data
echo json_encode($result_data);
答案 0 :(得分:4)
您正在将mysql与mysql混合使用。试试这个 -
$usersexist = mysqli_query($con, "SELECT phone FROM usersacc WHERE phone = '$pho'") or die(mysqli_error());
$count= mysqli_num_rows($usersexist);
if($count > 0) {
//rest of your code
答案 1 :(得分:1)
Mysql不是mysqli。您应该在这里使用$ userexist-> num_rows(对象上下文)或mysqli_num_rows($ userexist)程序上下文。另外你应该检查$ userexist是否只返回false(查询失败)。像这样:
$usersexist = mysqli_query($con, "SELECT phone FROM usersacc WHERE phone = '$pho'");
if(!$userexist)
die("query failed");
$count = mysqli_num_rows($userexist);
if($count > 0)
{
$result_data = array(
'ResultArray' => 'Exist',
);
}
else
{
mysqli_query($con,"INSERT INTO usersacc
(phone, password) VALUES('$pho', '$pass')");
#Build the result array (Assign keys to the values)
$result_data = array(
'ResultArray' => 'success',
);
}
#Output the JSON data
echo json_encode($result_data);
答案 2 :(得分:0)
mysql_num_rows($usersexist)
正确
mysqli_num_rows($usersexist)