开发者

Unable to compare valuesfrom mysql in a prepared statement

I can't seem to get this to connect to the database so that I can run my prepared statement. Does anybody have an idea what I've forgotten?

private function check_credentials($plain_username, $password)
  开发者_StackOverflow中文版  {
    global $dbcon;

    $ac = new ac();
    $ac->dbconnect();
    $userid = $dbcon->prepare('SELECT id FROM users WHERE username = :username AND password = :password LIMIT 1');
    $userid->bindParam(':username', $plain_username);
    $userid->bindParam(':password', $password);
    $userid->execute();

    $id = $userid->fetch();
    Return $id;
    }

EDIT: I changed the SQL query from a SELECT FROM query, to an INSERT INTO query and it worked. WHat the heck is going on?


Reformatting your stack backtrace:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound' in E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php:61
Stack trace:
#0 E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php(61): PDOStatement->execute(Array)
#1 E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php(34): ac->check_credentials('joe', '94a02c32b6ff629...')
#2 E:\PortableApps\xampp\htdocs\SN\UI\UIclass.php(17): ac->authentication()
#3 E:\PortableApps\xampp\htdocs\SN\index.php(4): ui->start()
#4 {main} thrown in E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php on line 61

Is there any reason you're instantiating a new ac object in the check_credentials function? Given that check_credentials is already a method of ac, this seems odd. Does dbconnect overwrite the global dbcon?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜