Hello i'm coding a social site and I need to know how clean this code is. I read other answers people told me from my previous questions like this and used it as guidelines. So now I wanna know if anything could be improved. Thank you.
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
error_reporting(-1);
include 'includes/header.php';
$userLoggedIn = $_SESSION['thesocial_username'];
$post_id = isset($_POST['cancel']) ? header("Location: settings.php") : '';
if(isset($_POST['close_account'])) {
$close_query = $con->prepare('UPDATE users SET user_closed = "yes" WHERE username = ?');
$close_query->bind_param("s", $userLoggedIn);
$close_query->execute();
session_destroy();
header("Location: register.php");
}
?>
<center>
<div class="close_column close_account">
<h4>Close Account</h4>
Are you sure you want to close your account ?<br><br>
Closing your account will hide your profile and activity from users.<br><br>
You can reopen your account at anytime by logging in.<br><br>
<form action="close_account.php" method="POST">
<input type="submit" name="close_account" id="close_account" value="Yes, Close my account.">
<input type="submit" name="cancel" id="update_details" value="Nevermind.">
</form>
</div>
</center>
$post_id
so I find it to be an inappropriate syntax. There's not much to review here. \$\endgroup\$ – mickmackusa Jul 10 '20 at 0:22if
for that. Actually the$post_id
variable should not be there at all. Further, you should exit the script after sending location header. I can close the account and get redirected to settings.php by postingcancel=1&close_account=1
. The script would actually send two location headers, I assume the browser will redirect to the adress of the first of them. \$\endgroup\$ – slepic Jul 10 '20 at 4:32$post_id
. I just took that code and threw in it there. I honestly don't know why but I was up for a long time trying to fix the code and I must've screwed up. Thanks a lot though. \$\endgroup\$ – user13477176 Jul 10 '20 at 21:03