0

I’m not sure where is the problem is to fix this:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

Here is the function:

 public function checkUS($US){
        if(isset ($_POST['submit'])){
            $detailsCheck = mysqli_query($this->objDbConn,"SELECT Username FROM * WHERE Username='$US'");
            $numRows = mysqli_num_rows($detailsCheck);


            if(!$numRows >=1){
                echo "<span id='errors'>This username is been use</span>";
                return false;
            }else{
                return true;
            }
        }
    }
Dharman
  • 30,962
  • 25
  • 85
  • 135
noooooooo
  • 1
  • 4
  • `$this->objDbConn` is false b/c you have some kind of connection error. You haven't given us the relevant code, but if you check the documentation you'll see where a boolean is returned. –  Jun 07 '14 at 06:00
  • 1
    @JeremyMiller “$this->objDbConn is false b/c…” Where does the poster say this is false? The query itself is a mess. And `Fluffeh` has given the answer. – Giacomo1968 Jun 07 '14 at 06:03
  • @JakeGould Thanks. I actually got a bit before myself and thought I had read that it was the query with the boolean given which would make my comment sensical. Since it was not the query, you are right and I am wrong in the area of analysis. The assertion about documentation and booleans, though, holds. –  Jun 07 '14 at 06:05

1 Answers1

3

$detailsCheck is not a valid query. You might be missing $US, you might have your query wrong or not have permissions to run it... but....

I am pretty sure that this:

SELECT Username FROM * WHERE Username='$US'"

is meant to be this:

SELECT * FROM Username WHERE Username='$US'"

If the query you run isn't valid, then you can't run mysqli_num_rows on it - hence the error message Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given meaning that $detailsCheck is currently false, which in turn means that mysqli_query returned false - ie didn't work.

Edit: To troubleshoot code, output as much info as you can. See where code stops working, throw out error and warning messages wherever you can. Add some error reporting to your objDbConn function. Track it down and sniff it out, I wager there is a good chance that when you see the error message you can solve it yourself without even thinking :)

Fluffeh
  • 33,228
  • 16
  • 67
  • 80
  • so how can I make it to true? and I still have the warning after i change to SELECT * FROM Username WHERE Username='$US'" – noooooooo Jun 07 '14 at 06:39
  • @noooooooo You don't want it as a `TRUE` you want it as a resource. The easiest way to determine *where* your code is going wrong is to enable [errors](http://au2.php.net/mysqli_error) which you can then use to pinpoint where the problem is. Without something specific, folks here can only guess at the problem - and that's not a good way to troubleshoot anything. See additional edit in answer. – Fluffeh Jun 07 '14 at 06:49