Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return to previous page after submit

Status
Not open for further replies.

rskuse

Technical User
Jul 18, 2002
74
GB
Hi,

Scenario:
I want to add a new topic to a page that has been passed an 'id' as a URL variable. I click on a link that takes me to a record insertion form (on a new page). I insert my data and hit submit to enter data into my database.

Question:
How do I then return to the page I originally clicked the link on?
(Baring in mind that this page has been passed an 'id' as a URL variable by a link from a previous page)

I have used Dreamweaver MX to create the record insertion form. The code to redirect to a page is as follows:

$insertGoTo = "subcat.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

I hope I've explained myself ok!

Thankyou in advance....

 
You have a few choices... if you haven't output anything to the screen you can do just like you did in the code you offered
Code:
header("Location: http:\\whereveryouwanttogo\");

or if you have output things you can use some javascript to do an automatic redirect.  Subject to the user having javascript turned on of course.
Rob
 
The problem is trying to redirect back to a page that has already been passed an id as a URL variable. At the moment I just return to subcat.php which returns id = 1 as this is the default.

Rach
 
You should look into session variables. That way the id can be kept over multiple PHP page access.

Also:
You know the ID on the page that you are on. The redirect can just pass that ID as a GET parameterin the URL string if you want. That's the other possibility.

In any case, sessions are the way to go.
The originating page with the clicked link should be available in $_SERVER['HTTP_REFERER'].
 
Hoi, was just browsing a few pages back lol.
Normally I find IE to be quite good at tracking history, therefore I use :

Code:
echo &quot;<form name=back action=\&quot;javascript:history.go(-2)()\&quot; method=post>&quot;;

echo &quot;<input type=submit value=\&quot;Go Back\&quot;>&quot;;

echo &quot;</form>&quot;;

this button skips the previous form and should put you where you want to be.


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
The only thing with the back button is that is works different on all kinds of browsers. I would not put any confidence into that.
People are not just using IE.
 
Good point, thanks for that!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top