Forums

PHP

This topic is locked

Variables Appended to URL

Posted 12 Jul 2006 19:07:09
1
has voted
12 Jul 2006 19:07:09 Matt Bailey posted:
I have a page that has content filtered from a database using a URL variable. The page also has a simple form that, when submitted, inserts a value in to the database and then redirects the user to a 'thank you' page using a PHP 'header' redirect.

My problem is this - the PHP 'header' redirect has URL variables as well (enabling me to show a custom message on the 'thank you' page) and when the form is submitted these are inserted into the existing URL, maintaining the existing URL variables.

For example, this is the URL to my main page:

www.jcl.so-design.co.uk/jcladmin/index.php?PageID=7

When the form is submitted this is what happens to the URL:

www.jcl.so-design.co.uk/jcladmin/index.php?PageID=10&MessageID=5&PageID=7

As you can see there are two 'PageID' variables and the second seems to cancel out the first, meaning the 'thank you' page does not load, it simply stays on the same page, but the database does get updated though.

Any suggestions?

___________________________________
"Some people say if you play a windows cd backwards it plays satanic messages. That's nothing, because if you play it forwards it installs windows!"

Replies

Replied 13 Jul 2006 11:28:58
13 Jul 2006 11:28:58 Roddy Dairion replied:
How does the code appears in your header() function?
Replied 13 Jul 2006 11:49:38
13 Jul 2006 11:49:38 Matt Bailey replied:
Hi Roddy, I appear to have solved the problem, but I'll post my solution here in case anyone else needs to know.

This is how the original code appeared:

<pre id=code><font face=courier size=2 id=code>header("Location: /jcladmin/index.php?PageID=10&MessageID=5";</font id=code></pre id=code>

And this is what I changed it to:

<pre id=code><font face=courier size=2 id=code>if (isset($_GET['PageID'])) {
header("Location: /jcladmin/index.php?PageID=10&MessageID=5";
}</font id=code></pre id=code>

It seems that checking first if the url variable is set (PageID) makes the whole url load again, rather than simply appending the new url variables to the existing url.

___________________________________
"Some people say if you play a windows cd backwards it plays satanic messages. That's nothing, because if you play it forwards it installs windows!"

Reply to this topic