mardi 25 août 2015

SQLite and PHP register system not working

This is my registration code using PHP and SQLite. It keeps going to the statement "user already exists" when it certainly does not. I check to see if the username is greater than one in the database (if it exists) and it does not, but if I echo out the count it always says its equal to one...

$checkUser = $db->prepare('
    SELECT COUNT(*) 
    FROM users
    WHERE 
    user = ?
');

$checkUser->setFetchMode(PDO::FETCH_ASSOC);
$checkUser->execute(array($user));


$numrows = count($checkUser);

if ($numrows == 0) {

    try {

        $reg = $db->prepare("
            INSERT
            INTO users
            (user, pass, email)
            VALUES
            ('$user', '$pass', '$email')  
        ");

        $reg->setFetchMode(PDO::FETCH_ASSOC);
        $reg->execute();

    } catch (PDOException $e) {
        print_r($e->getMessage());
    }

    echo ('success...');
}
else {


    die ('user already exists');
}

Aucun commentaire:

Enregistrer un commentaire