duandie5707
duandie5707
2019-03-06 00:15

第一次尝试我正在登录/注册表格。 得到一个错误

已采纳

Hey guys I'm working on a login/register for and I'm struggeling with the following things. When registering there's a message (registration complete) but there's also an error I can't get rid off.

Als when the username is already taken there should be a message that says that but there isn't. The error I get is the following.

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool 
given in C:\xampp\htdocs\testegistration.php on line 16

The code I use in registration.php is

<?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";
}

?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dragon8837 dragon8837 2年前

    I believe you may have a typo in your code

    $s = "select * from usertable where name = 'name' && passoword = '$pass'";
    

    I assume that passoword should be password. Also, name should be $name

    $s = "select * from usertable where name = '$name' && password = '$pass'";
    

    As others have suggested, your code is vulnerable to SQL injection and should NOT be used in production.

    点赞 评论 复制链接分享