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条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用