if ($stmt = $dbconn->prepare('INSERT INTO `astm_clients_tbl` (`u_name`, `u_email`, `u_password`, `u_plain_password`, `u_phone`, `u_referral_id`, `u_referrer`, `u_join_date`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('ssssssss', $auth_name, $to, $password, $plainPass, $tel, $ref_id, $ref, $join_date);
$stmt->execute();
header('Location: register.php?msg=success');
exit();
$stmt->close();
} else {
header('Location: register.php?msg=error');
exit();
}
Asked
Active
Viewed 29 times
-1

Barmar
- 741,623
- 53
- 500
- 612

user19118521
- 1
- 3
-
1Do **NOT** store plain password in db please – Ken Lee Sep 15 '22 at 23:28
-
You should check the result of `$stmt->execute()`. – Barmar Sep 15 '22 at 23:33
-
`$stmt->close()` will never be executed, since `exit()` ends the script. – Barmar Sep 15 '22 at 23:33
-
You should log the reason for the error so you can troubleshoot it. `error_log($dbconn->error);` – Barmar Sep 15 '22 at 23:34
1 Answers
-2
$stmt->execute()
returns bool. Check if it's True
before redirecting.
Take a cue below
if ($stmt = $dbconn->prepare('INSERT INTO `astm_clients_tbl` (`u_name`, `u_email`, `u_password`, `u_plain_password`, `u_phone`, `u_referral_id`, `u_referrer`, `u_join_date`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('ssssssss', $auth_name, $to, $password, $plainPass, $tel, $ref_id, $ref, $join_date);
if ($stmt->execute()) {
header('Location: register.php?msg=success');
exit();
$stmt->close();
}
} else {
header('Location: register.php?msg=error');
exit();
}

ForALLs
- 27
- 5
-
It's bad practice to check each method call for errors manually. Instead enable mysqli error reporting. – Dharman Sep 15 '22 at 23:40
-
-
header('Location: register.php?msg=error'); is extremely unhelpful and practically useless – Your Common Sense Sep 16 '22 at 06:34