0
if($_POST){

    if($checkout_form == "checkout"){
        if($orderpersonname == "" || $orderpersonemail == ""){
            $checkouterror = "<p><font style=\"color: red;\">Please enter your full name and email address before checking out</font></p>";
        }elseif(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $orderpersonemail)){
            $checkouterror = "<p><font style=\"color: red;\">Please enter a valid email address</font></p>";
        }elseif(!isset($_POST['tnc'])){
            $checkouterror = "<p><font style=\"color: red;\">Please accept the terms and conditions to complete this entry before checking out</font></p>";
        }
        else{
            header("Location: http://www.google.com.my");
            exit;


        }
    }
}

I have the code above if there's no error occur it will redirect me to a checkout page, in this case I use google page as a sample. But what it does is actually brings me back to the same URL and there's a blank space above my website header and all the sidebar and content become blank. Why is that so? How to solve this redirection issue?

3 Answers3

0

Use ob_start() for this issue. I think it will solve your issue.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
JayminLimbachiya
  • 971
  • 1
  • 13
  • 19
0

One main issue I have ran into with these is the headers were already sent. Try using ob_start().

As said above, this will not do anything if you have whitespace...

ykykykykyk
  • 446
  • 1
  • 3
  • 10
0

You don't have your braces in right positions.

if ($_POST){
    if ($checkout_form == "checkout") {
        if($orderpersonname == "" || $orderpersonemail == "") {
            $checkouterror = "<p><font style=\"color: red;\">Please enter your full name and email address before checking out</font></p>";
        }elseif(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $orderpersonemail)) {
            $checkouterror = "<p><font style=\"color: red;\">Please enter a valid email address</font></p>";
        }elseif(!isset($_POST['tnc'])) {
            $checkouterror = "<p><font style=\"color: red;\">Please accept the terms and conditions to complete this entry before checking out</font></p>";
        }
    } else {
        header("Location: http://www.google.com.my");
        exit;
    }
}
Cyril Joudieh
  • 132
  • 2
  • 15