views:

157

answers:

1

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)
    {
    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?

+1  A: 

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?

Marc B
Honestly, I have no reason for it other than I thought that's how it worked. Let me change it and see if it works
Cortopasta
no luck //Stupid character limits for comments at SO
Cortopasta
About all I can suggest is var_dump/print_r the $dbcon and $userid after each step, see if anything funky shows up in there.
Marc B