何らかの理由で、次のコードは、パラメーターが何であり、SQL行の実際に何が含まれているかに関係なく、常にtrueを返します。また、「通知:7行目のC:\ wamp \ www \ Social Networking \ INC \ login.incの通知:未定義のオフセット:0」というエラーもスローされますが、何が問題なのかわかりません。
<?php
function checkAccount($username, $password){
include("INC/dbconnect.inc");/*"INC/dbconnect.inc" is <?php $pdo = new PDO("mysql:host=localhost;dbname=socialnetwork","user","123"); ?>*/
$select = $pdo->prepare("SELECT id,password FROM users WHERE user_username = :username");
$select->execute(array(':username'=>$username));
$q_rows = $select->fetchAll();
if($q_rows[0][0]/*the ID of the user, it should always be greater than 1, if not then the username does not exist*/ > 0 && $q_rows[0][0] != null){
if($q_rows[0][1]/*the password of the user*/ == $password)
return true;
else
return false;
}
else
return false;
$pdo=null;
} ?>
誰かが何が悪いのか教えてもらえますか?私はコード内で私が経験している問題についてコメントしました、そして私は役に立たない$select->fetch()
代わりに通常のことを試みました。$select->fetchAll()
これを投稿する前に、PDOについて読んだことがあります(http://php.net/manual/en/pdostatement.fetchall.php)。これが私のファイルの残りの部分ですhttp://pastebin.com/YCkrRivs、ありがとう。