// goto is STILL a good feature if you know how to use it.
// Just don't use it in loops.
// Example:
$sql = "DELETE FROM sometable WHERE id=?;";
$stmt = $conn->prepare($sql);
if (!$stmt) {
echo "ERR prepare_fail";
goto End;
}
$bind = $stmt->bind_param('i', $id);
if (!$bind) {
echo "ERR bind_fail";
goto End;
}
$exec = $stmt->execute();
if (!$exec) {
echo "ERR exec_fail";
goto End;
}
if (isset($_POST['file'])) {
$file = "../" . $_POST['file'];
if (is_file($file)) { unlink($file); }
}
echo "OK delete_success" ;
End:
$stmt->close();
$conn->close();
exit;
/*
instead of repeating the $stmt->close() and $conn->close(),
we save a few lines by adding a goto and just close everything at the end.
*/