简体   繁体   中英

Return to previous page and refresh it in php?

I have a submit form and while submitting the form it will load a php for the process like insert to DB and all.For going back to the submit form I added

 header("location:javascript://history.go(-1)");

But how to reload the page (the submit form page so user can see the submitted form details)

Try something like this:

<form method="POST" action="">
  <input type="text" name="surname" value="<?php echo $_POST["surname"]; ?>" <?php echo (empty($_POST['surname']) ? "" : "disabled='true'"); ?>>
  <input type="submit" value="Submit" name="submit">
</form>

<?php
    if(isset($_POST['submit']))
    {
       //insert to db
       echo "success";
    }
?>

try redirecting to previous page redirectin will cause the browser to make a new http request refreshing the page content to get the previous page address you can use HTTP_REFERER

$previousPage = $_SERVER["HTTP_REFERER"];
header('Location: '.$previousPage);

this will cause the browser to re-navigate to the previous page

After submit the form data, you should check data exist or not. if exist you would be fetch data from Database & render the view file.

Something like

function somthing() {
    if($_POST[]) {
        // inser data into DB
        // then
        // fetch last inserted row from DB
        render view file with fetched row values
    }

    render view file without  fetched row values
}

this is not a proper way to show data to user. you have to create separate forms to submit values & show the values on html. each time when user click on it the sql query run & show related data.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM