请帮助我在PHP中的这些错误

时间:2018-01-06 10:28:26

标签: php

警告:mysqli_query()需要至少2个参数,1在第6行的C:\ xampp \ htdocs \ cms \ users \ check_availability.php中给出

警告:mysqli_num_rows()期望参数1为mysqli_result,在第7行的C:\ xampp \ htdocs \ cms \ users \ check_availability.php中给出null

<?php 
require_once("includes/config.php");
if(!empty($_POST["email"])) {
	$email= $_POST["email"];
	
		$result = mysqli_query("SELECT userEmail FROM users WHERE userEmail='$email'");
		$count = mysqli_num_rows($result);
if($count>0)
{
echo "<span style='color:red'> Email already exists .</span>";
 echo "<script>$('#submit').prop('disabled',true);</script>";
} else{
	
	echo "<span style='color:green'> Email available for Registration .</span>";
 echo "<script>$('#submit').prop('disabled',false);</script>";
}
}


?>

2 个答案:

答案 0 :(得分:1)

您显然缺少$connection$link,这里的数据库连接

$result = mysqli_query($conn, "SELECT userEmail FROM users WHERE userEmail='$email'");

mysqli_num_rows($result);

答案 1 :(得分:1)

你需要创建一个mysqli连接的对象。你必须在mysqli函数中传递两个参数,一个是db连接对象,第二个是query.Please参考下面的链接 https://www.w3schools.com/php/func_mysqli_query.asp