duandie5707 2019-03-06 00:15
浏览 194
已采纳

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

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 2019-03-06 00:44
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大