0

I was trying to make an html button load some sql script, and the way I figured best to do it was with an html form using post method and loading another php page which contains the script. The problem is it then just shows a blank page once it completes but I would rather reload the previous page.

Originally I wanted to just load the script on the same page and refresh it but found this to be easier.

Here is what I have so far:

<form action="move_to_processing.php" method="post" onsubmit="return confirm('Are you sure you want to move them??');">

    <input type='submit'   name='hehe'  value="Move to processing"  />
</form>

and then the page move_to_processing.php loads which is just a page with the sql. This is working right now.

I tried doing the following to just reload the current page (orders.php) but it didn't seem to work:

<form action="orders.php" method="post" onsubmit="return confirm('Are you sure you want to move them??');">
    <input type='submit'   name='hehe'  value="Move to processing"  />
</form>


<?php
if(isset($_POST['hehe'])){
    tep_db_query("update orders o set o.orders_status= 13 where o.orders_status = 12");
}

}
Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
Sackling
  • 1,780
  • 5
  • 37
  • 71
  • 3
    Does this answer your question? [How do I make a redirect in PHP?](https://stackoverflow.com/questions/768431/how-do-i-make-a-redirect-in-php) - Just redirect the user where you want at the end of the PHP script. – M. Eriksson Dec 17 '19 at 14:49

1 Answers1

1

After you execute your function, you add Location header to your response, and then immediately end script execution. When the browser receives the Location header it will redirect the user to that page.

<?php

// orders.php

if(isset($_POST['hehe'])){

  tep_db_query("update orders o set o.orders_status= 13 where o.orders_status = 12");
  header('Location: /previous-url');
  exit();

}
?>
besciualex
  • 1,872
  • 1
  • 15
  • 20
  • The OP already mentioned that the form and the PHP code are on two different pages so there's no need for any output buffering. It might actually confuse more than it helps in this context. – M. Eriksson Dec 17 '19 at 15:02
  • @MagnusEriksson indeed it did, but soon after this he updated his code and by the way it looks there it looks like the same page. – besciualex Dec 17 '19 at 15:09
  • 1
    @MagnusEriksson I have updated the code example so it won't be as confusing as before. :) – besciualex Dec 17 '19 at 15:11