Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My php page is not redirecting to the success page in the online so many said ob_start() and ob_flush() functions I added but there is no use please find the code below.Details are entering successfully in a database but not redirecting.

What I have tried:

<!DOCTYPE html>
<html>
<body>
<?php
ob_start();
?>
<?php 
if(isset($_POST['name'],$_POST['email'],$_POST['mobile'],$_POST['comment']))
{
  $name = $_POST["name"];
  $email = $_POST["email"];
  $mobile = $_POST["mobile"];
  $comment = $_POST["comment"]; 
  echo "name: $name, email: $email, mobile:$mobile, comment:$comment";
  $servername = "localhost";
  $username = "XXXX";
  $password = "****";
  $dbname = "$$$$$";
  // Create connection
  $conn = mysqli_connect($servername, $username, $password, $dbname);
  // Check connection
  if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
  }
  echo "Connected successfully";
  if($name !=""){
    echo "There are no null values";
    $sql = "INSERT INTO `customerinfo` (`name`, `email`, `mobile`, `comment`)
    VALUES ('$name', '$email', '$mobile', '$comment')";
  }
  if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
  } else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  }
  mysqli_close($conn);
}
?> 
<?php
header("Location: success.php"); 
exit;
?>
<?php 
ob_end_flush();
?>   
</body>
</html>
Posted
Updated 24-Jul-17 23:44pm
v2

1 solution

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

Use your debugger to check what happening there...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900