jeudi 22 octobre 2015

How can php not execute neither 'then' nor 'else' clauses of 'if'?

Following this tutorial (which I adapted to PostgreSQL), I have a problem in register.inc.php:

if (empty($error_msg)) {
    // Create a random salt
    $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
    // Create salted password 
    $pwd = hash('sha512', $pwd.$random_salt);
    // Insert the new user into the database 
    $q = "insert into usr (username,email,pwd,salt) values ($1,$2,$3,$4);";
    $res = pg_query_params($conn,$q,[$username,$email,$pwd,$random_salt]);
    if ($res === false) {
        header("Location: ../html/coisas/error.php?err=Registration failure: INSERT");
    } else {
        header('Location: ./register_success.php?msg=1'.$random_salt);
    }
    header('Location: ./register_success.php?msg=2'.$random_salt);
}

The header sent is the 3rd one (?msg=2...). If I comment it out, there's no header sent. How can it be that it won't enter in the then clause, nor in the else clause? The data is not being stored in the database, but I'm getting a "sucess" response. How can I know for sure the value of $res?

Aucun commentaire:

Enregistrer un commentaire