-3
我的數據庫中有一行(與WHERE語句相同),所以輸出結果必須是1,所以需要說'Account Bestaat'。mysqli count rows錯誤
當我打印$帳戶時,它會在我的數據庫中打印1個數組,因此我的腳本與數據庫有良好的連接。但是,當我要算行它給出了一個錯誤:
mysqli_num_rows() expects parameter 1 to be mysqli_result, null given.
我不是mysqli的那麼好,因爲我之前使用的mysql_query。
我該如何解決這個問題,以便$ num_account輸出「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';
}
因爲結果$ account_raw沒有$帳戶 – clearshot66
[小博](http://bobby-tables.com/)說***腳本是在對SQL注入攻擊的風險。(HTTP ://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)***瞭解[prepared](http://en.wikipedia.org/wiki/Prepared_statement) [MySQLi]的聲明(http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)。即使[轉義字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! –
並請學會使用準備好的語句,因爲這完全不安全 – clearshot66