嘿伙计们,我正在登录/注册,我正在努力解决以下问题。注册时有一条消息(注册完成),但也有一个错误,我无法摆脱。
如果已经使用了用户名,则应该有一条消息说明但没有。我得到的错误如下。
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool
given in C:\xampp\htdocs\test\registration.php on line 16
我在registration.php中使用的代码是
<?php
session_start();
$con = mysqli_connect('127.0.0.1','jstam','12345');
mysqli_select_db($con, 'userregistration');
$name = $_POST['user'];
$pass = $_POST['password'];
$s = "select * from usertable where name = 'name' && passoword = '$pass'";
$result = mysqli_query($con, $s);
$num = mysqli_num_rows($result);
if($num == 1){
echo"Gebruikersnaam in gebruik";
}else{
$reg= "insert into usertable (name , password) values ('$name' , '$pass')";
mysqli_query($con, $reg);
echo"Registratie succevol";
}
?>
我相信你的代码中可能有拼写错误
$s = "select * from usertable where name = 'name' && passoword = '$pass'";
我假设passoword应该是密码。此外,名称应为$ name
$s = "select * from usertable where name = '$name' && password = '$pass'";
正如其他人所建议的那样,您的代码很容易受到SQL注入的攻击,因此不应该在生产中使用。