Home Ask Login Register

Developers Planet

Your answer is one click away!

Ryan February 2016

"Double Load" Issue with PHP isset() and $_POST data

I know I am doing something wrong by using a combination of isset(), $_POST and $_GET but I am wondering what would be the easiest and painless way to tackle my issue.

The issue arises when I submit a HTML form... It reloads the page with the post data. I capture the submit with a php isset() function, process the $_POST data and then run a window.location to refresh the page with some $_GET data.

For example...


<form action="" method="post">

  <input name="stage1name" type="text" class="textfield" size="22" value="<?php echo $ClaimRow['ClaimantName']; ?>">
  <input name="VehicleEngine" type="text" class="textfield" size="20" value="<?php echo $vehiclerow['VehicleEngine']; ?>">
  <input name="VehicleFuel" type="text" class="textfield" size="20" value="<?php echo $vehiclerow['VehicleFuel']; ?>">

  <input name="submitInfo" type="submit" value="<?php echo $LANG_Claims_Change_Info; ?>" />



    if (isset($_POST['submitInfo']))
        $stage1name= mysqli_real_escape_string($db, $_POST['stage1name']);
        $VehicleEngine= mysqli_real_escape_string($db, $_POST['VehicleEngine']);
        $VehicleFuel= mysqli_real_escape_string($db, $_POST['VehicleFuel']);
        mysqli_query($db, "DO SOME COOL SQL HERE");

        //I've done what I need to do so lets reload the page with the updated data

        echo "<script>window.location='example.php?vehicle=" . $vehicleID . "&claimTab=Personal'</script>";


Like I said before, this method works fine however the user gets the effect of a "double load" and is very epiletic fit inducing.

Any ideas how best to combat this?


EDIT - Additional Example

I realised that this one example might not make complete sense so I put together another example which hopefully will.




FarZan Takhsha February 2016


echo "<script>window.location='example.php?vehicle=" . $vehicleID . "&claimTab=Personal'</script>";


echo "<META HTTP-EQUIV = 'Refresh' Content = '0; URL =example.php?vehicle=" . $vehicleID . "&claimTab=Personal'>";

Ryan February 2016

After much testing. It turns out CMorriesy was correct. However for future reference you will need to turn output_buffering = on in php.ini and also add <?php ob_start(); ?> to the very first line of your code.

header('Location: example.php?vehicle=' . $vehicleID . '&claimTab=Personal'); die();

Post Status

Asked in February 2016
Viewed 2,410 times
Voted 10
Answered 2 times


Leave an answer

Quote of the day: live life