if statement - How can php not execute neither 'then' nor 'else' clauses of 'if'? -
following this tutorial (which adapted postgresql), have problem in register.inc.php
:
if (empty($error_msg)) { // create random salt $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true)); // create salted password $pwd = hash('sha512', $pwd.$random_salt); // insert new user database $q = "insert 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 3rd 1 (?msg=2...). if comment out, there's no header sent. how can it won't enter in clause, nor in else clause? data not being stored in database, i'm getting "sucess" response. how can know sure value of $res
?
a header()
work if sent before other output sent browser. guess have sent browser, maybe debugging message or something.
if has happened should see self explanitory error message in php error log
also should exit;
after header()
statement header()
not stop execution of rest of script.
i.e.
if ($res === false) { header("location: ../html/coisas/error.php?err=registration failure: insert"); exit; } else { header('location: ./register_success.php?msg=1'.$random_salt); exit; } header('location: ./register_success.php?msg=2'.$random_salt); exit;
Comments
Post a Comment