-2

I want to redirect to index.html?id=div2 when the if condition is statisfied. And if not, then it should reload the page.

How do I do that?

if($checkAll > 0){
    // Redirect to index.html?id=div2  
} else{
    //Reload page
}

Thanks!

Leena
  • 219
  • 2
  • 10

3 Answers3

0

You have to use headers:

if($checkAll > 0){
    header("Location: /index.html?id=div2"); 
} else{
    header("Refresh:0");
}
// die();
Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48
0

/* Redirect browser */

header("Location: yourUrl.com");
exit();

it's a good practice to call exit() right after it so that code below it does not get executed.

0

Try this, I use redirect like this.

function redirect_to($location) {
    header("Location: " . $location);
    exit;
}


if($checkAll > 0) {
    $new_id = mysqli_insert_id($connection);
    redirect_to('/index.php?id=' . $new_id);
      } else {
    redirect_to('/index.php');
}
Mantykora 7
  • 173
  • 2
  • 8
  • 19