doudian6229 2015-08-06 11:18
浏览 53
已采纳

注册脚本 - mysqli_num_rows()期望参数1为mysqli_result [duplicate]

What I am trying to do:

Trying to create a register php script that works. Basically I need new records in my table.

Problem:

I am learning php and trying to find out how to solve, after loads of fixing, this last error message which I absolutely dont understand.

What I tried:

I set up the database and wrote the script. After that I encountered 13 errors from which I only fixed 12. The remaining one really gives me a hard time. I know it has something to do with mysqli_result but no idea how to implement it. I did try this:

$amount = mysqli_num_rows(mysqli_result, $result);

Error message:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given on line 22

<?php

    $connection = mysqli_connect("localhost", "root", "", "project")
    or die("cant connect");

$name = $_POST["name"];
$email = $_POST["email"];
$age = $_POST["age"];
$about = $_POST["about"];
$occupation = $_POST["occupation"];
$special_talent = $_POST["special_talent"];
$password = $_POST["password"];
$repeat_password = $_POST["repeat_password"];

if($password != $repeat_password OR $name == "" OR $password == "")
    {
    echo "Error";
    exit;
    }

$result = mysqli_query($connection, "SELECT id FROM members WHERE name, email LIKE '$name', '$email'");
$amount = mysqli_num_rows($result);

if($amount == 0)
    {
    $record = "INSERT INTO members (name, email, age, about, occupation, special_talent, password, repeat_password) VALUES ('$name', '$email', '$age', '$about', '$occupation',  '$special_talent', '$password', '$repeat_password')";
    $register = mysqli_query($connection, $record);

    if($register == true)
        {
        echo "Congratulations $name, you are now a Member!</a>";
        }
    else
        {
        echo "Unfortunately the registration failed. Try again please.</a>";
        }
    }

else
    {
    echo "Username already in use";
    }

?> 
</div>
  • 写回答

2条回答 默认 最新

  • dongyouji7022 2015-08-06 11:21
    关注

    $result is returning false. Your query has an error in it.

    Change from

    SELECT id FROM members WHERE name, email LIKE '$name', '$email'
    

    To

    SELECT id FROM members WHERE name LIKE '$name' AND email LIKE '$email'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!