Heres my problem.

I have a page that allows users to pick a date using a javascript calendar popup.

The return value from the popup is then sent to the main page using POST - so the page loads, grabs data from a MySQL database and prints the information out. It's tabular data, so I simply drop it in a table. (I know - dont get on my case about tables - they work for tabular data very well)

Next to each returned item are a few buttons, icons that allow the person to change status or provide information to the site. Buttons like Cancel, Increment, Enter Location. A simple yes/no, no popup or enter a value.

echo'<input type = "image" src="check.gif" alt="X" onClick ="change_status('.$a.','.$m.','.$d.','.$y.')">';

Currently, they click the icon, a javascript alert box asks them to confirm the action or provide an input value and then it calls another php page that updates the database accordingly.

The function is simple: (yes, I know I can strtodate and such, but this was brute force)

function change_status($a,$m,$d,$y)
{
var r=confirm("Confirm Status Change or press Cancel to go back");
if (r==true)
{
window.location = "http:modifyrecord.php?id="+$a + "&date="+$m+"-"+$d+"-"+$y;
}
}

So far, so good.

Then the page returns to the previous page using an inline javascript that just does a window.location="themainurl" - but since the POST data is gone, they get sent back with no POST data and the PHP page defaults to loading the data from "today" using php code like this:

if (isset($POST['date']))
$date = $
POST['date'];
else if (isset($GET['date']))
$date = $
GET['date'];
else
$date = date('Y-m-d');

To remedy this, I send the date to the javascript function and it passes that along to the next php page
echo'<input type = "button" value = "Go Back To Schedule" onClick="goback('.$m.','.$.','.$y.')">';

the goback function just creates the window.location= values sending the data via GET something like href="themainurl?date='$date' call.

Since I handle both get and post in my script I don't really care which way it gets back. The problem is, that I have solved the problem of changing pages, but caused an additional button click to return to the schedule. Since they handle about 500 items a day, this is 500 additional clicks that I need to get rid of.

Ideally, I would like to have the php page be able to call either a javascript or php function that can:

1) Ask for confirmation or Input
2) Based on the input, handle the database update
3) Return to the page we came from WITH the POST/GET data intact.

I thought about creating a php function on the page - and I can do that, but there is no way to get the input I need to "continue" as the alert box method seems to be the simplest way.

So, how can I do this? Can I process a MySQL update on a page and then redirect to the previous page (or another page) with the POST/GET data intact? Can I process the MySQL from a javascript somehow? I seem to be dealing with server side vs client side between PHP and javascript - and neither can do the entire thing. I can't rewrite the entire setup.

Any ideas?

I have been searching for days and trying all kinds of things... No luck.

    The answer to your problem seems to be AJAX.
    The way it would work:
    - gather your input the normal way
    - send an asynchronous request to the server (you don't even leave the current page, so no need to preserve $GET or $POST), the saving in database would be in separate php script.
    - the request returns some value (possibly, the result of the database operations), which you can use to alter the loaded page to reflect the changes.

    There are many AJAX tutorials on the internet, so no need to reinvent the wheel and write one in this post.

      Ignore this if I'm telling you something you already know, but POST and GET are very different things.

      POST should be used when you don't want someone to repeatedly submit a form. Use it for things like updating someone's profile or submitting an order. When you POST data, the browser knows this and if you click your browser's back/next buttons and revisit a page that is the result of POST data, the browser will prompt you "are you sure you want to resend data". As a general rule, I use POST for expensive operations.

      It's also good practice when someone submits a POST operation to show them a 'data received' message and immediately redirect them to another page using a META redirect. This prevents the data from being POSTed again if the user refreshes the page.

      GET should be used when you want information to be easily retrieved from a given URL. A user can copy the URL, give it to a friend, and they'll see the same thing. I use it as much as possible for paged results (e.g., "showing records 1-25 of 234 records prev/next").

      Another difference is that POST can handle enormous amounts of data and file uploads. GET has a limit on the amount of information you can pass. Browsers differ, but I try to limit the length of a given url to some reasonable length. I think the practical upper limit should be about 2,000 chars (which in my opinion is way too long) if you want to make sure it works in all common browsers.

      Not sure why you'd be using post in this context. Is someone logging in? Is it a search? If you want to preserve information submitted in a POST operation, consider using sessions. You could so something like

      // this is the page that handles the post
      session_start();
      $_SESSION['post_data'] = $_POST;
      
        Write a Reply...