Hi Guys trying to find the mistake page not changing to index.php.
Not Redirecting to landing page everything else works fine.
Record is deleted from db, page with delete yes/no also ok
<?php
// Process delete operation after confirmation
if(isset($_POST["ID"]) && !empty($_POST["ID"])){
// Include config file
require_once 'config.php';
// Prepare a select statement
$sql = "DELETE FROM cv WHERE ID = ?";
if($stmt = mysqli_prepare($link,$sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_ID);
// Set parameters
$param_ID = trim($_POST["ID"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records deleted successfully. Redirect to landing page
header('Location:index.php');
exit;
}else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
// Close connection
mysqli_close($link);
} else{
// Check existence of ID parameter
if(empty(trim($_GET["ID"]))){
// URL doesn't contain ID parameter. Redirect to error page
header("location: error.php");
exit();
}
}
?>
Any help would be great.
Warning: Cannot modify header information - headers already sent by (output started at /storage/public_html/crudbd/config.php:31) in /storage/public_html/crudbd/delete.php on line 26
As soon as you echo ANYTHING , HTTP headers get sent, thereby making it impossible to send any more, causing your redirect header to FAIL.
Check for echo statements in config.php, and turn display_errors off, error_reporting to -1, and tail the log in the terminal to make sure any error log stuff isnt causing PHP to output early.
UPDATE
You pasted your error. Warning: Cannot modify header information - headers already sent by (output started at /storage/public_html/crudbd/config.php:31) in /storage/public_html/crudbd/delete.php on line 26
So, as I said, I was correct in guessing that there was output in config.php, however it wasn't an echo.
If you turn display_errors
off, it should work. The notice or warning will still appear in your log.
Find out what is happening on that line. If there is an undefined variable which you don't first check with isset()
for example, that could trigger log output.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.