我有一个问题,我似乎无法使用我的注册脚本解决。
这是脚本:
<?php
//MySQLi connection
$con = mysqli_connect("-","-","-","users");
if (mysqli_connect_errno())
{
echo "MySQLi Connection was not established: " . mysqli_connect_error();
}
//Reading the userdata from the registerp.php page
$usr = mysqli_real_escape_string($con,$_POST['username']);
$email = mysqli_real_escape_string($con,$_POST['email']);
$pass_unhashed = mysqli_real_escape_string($con,$_POST['pass']);
$pass = password_hash($pass_unhashed, PASSWORD_DEFAULT);
//Checking if user exists
$check_usr = mysqli_query($con,"SELECT * FROM users WHERE user_name = '$usr'");
if(check_usr === false)
{
echo(mysqli_error($con));
}
else
{
if (mysqli_num_rows($con,$check_usr)>=1)
{
echo "This Username already exists";
}
else
{
echo "This Username is available";
echo " Name: $usr";
}
}
?>
我的问题是我无法使验证工作(因此他们无法创建两个具有相同名称的帐户)。
mysqli_num_rows
总是返回0(“此用户名可用”),即使我的table
此外,它似乎也没有给我任何错误..
我做错了什么/我该怎么做才能解决它?
答案 0 :(得分:6)
mysqli_num_rows()接受结果集(mysqli_query()
或mysqli_store_result()
或mysqli_use_result()
)的单个参数,所以它应该是,
mysqli_num_rows($check_usr);