-3

There is 1 row in my database (that's equal with the WHERE statement) so the output needs to be 1, so it needs to say 'Account Bestaat'.

When I print the $account it prints 1 array thats in my database so my script has a good connection with the db. But when I want to count the rows it gives an error:

mysqli_num_rows() expects parameter 1 to be mysqli_result, null given.

I'm not so good with mysqli because I used mysql_query before.

How can I fix this so the $num_account should output "1"?

            $connectie = mysqli_connect('localhost','*','*', '*') or die (mysqli_connect_error() . '<br><br>Kan geen verbinding krijgen met de almachtige timo server :D');
            $account_raw = mysqli_query($connectie,"SELECT * FROM accounts WHERE gebruikersnaam='".$gebruikersnaam."' AND wachtwoord='".$wachtwoord."'");
            $account = mysqli_fetch_assoc($account_raw);
            $num_account = mysqli_num_rows($account);   

            if($num_account == 1){
                echo 'Account Bestaat';
            }
            else {
                echo 'Account Bestaat Niet';
            }
  • 1
    Because the result is $account_raw not $account – clearshot66 Sep 01 '17 at 20:11
  • 1
    [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)*** Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Sep 01 '17 at 20:12
  • and please learn to use prepared statements as this is entirely unsecure – clearshot66 Sep 01 '17 at 20:12

1 Answers1

3

Try this.

mysqli_num_rows($account_raw);   
tanaydin
  • 5,171
  • 28
  • 45