My users arrive on the page, optionally with a query string.

The query string data - if present - goes into a textarea element in a form, where it may be edited, then POSTed back to the page with the submit button.

Now I have a bit of a mess because the query string, which was ignored when the the form posted data, is showing obsolete information.

i.e. the user arrives with ?fruit=apple, changes apple to pear in the form, submits the form, now the form says pear, (and I've goe my pear products listed below, which is the point of the page) but the query string still says ?fruit=apple.

That seems harmless, but it's messy and may confuse the user.

So what I want is to clear the query string from the URL whenever the form is posted.

Clear as mud?

I hope someone can offer a suggestion, I'm stumped.

What has the action attribute of your form been set to? If form posts to the same page (#) then set the action to the page name without the querystring, something like:

$action = parse_url(__FILE__, PHP_URL_PATH);
echo "<form action='$action'>";
...

Dang, just answered my own question.

<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">

Headslap.

Thanks broj1, you must have been posting just as I was slapping my head.

Doh!

Don't slap it too hard, you might still need it :-)

This page dates way back and I was modifying it. It had some pretty bad syntax from my early days in PHP that somehow hadn't been breaking the page until my new code was put in. Jumped up and bit me!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.