For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > April 2006 > Pass value to header?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Pass value to header?
Garry Jones

2006-04-28, 6:58 pm

When processing a form I am reading in a value to a mysql database. I then
redirect the user to a "thank you" page with Header. What I would like is to
remind the user the value he/she keyed in. Can I pass the variable in the
Header command?

What I want to do in the following is echo the value of $inx01 in
thankyou.php?

<?php
mysql_connect(" Codes Removed ") or die(mysql_error());
mysql_select_db(" Database Name removed ") or die(mysql_error());

$inx01=$_POST['fardvagonf'];

mysql_query("INSERT INTO table1 VALUES ('$inx01')");
echo mysql_error();

mysql_close();

Header("Location: http://www.mydomain.com/thankyou.php");
exit;

?>

Garry Jones
Sweden


Ken Robinson

2006-04-28, 6:58 pm

Garry Jones wrote:
> When processing a form I am reading in a value to a mysql database. I then
> redirect the user to a "thank you" page with Header. What I would like is to
> remind the user the value he/she keyed in. Can I pass the variable in the
> Header command?


[snip]

> Header("Location: http://www.mydomain.com/thankyou.php");
> exit;
>


There are two different methods you can use:
1) Put the value into a session variable. Before the 'header()"
function, put

$_SESSION['inx01'] = $inx01;

Then in the thankyou.php script, you can get the value by referencing
$_SESSION['inx01']

Be sure you put

session_start();

at the start of each script.

2) Pass the value on the URL:

header('Location: http://www.mydomain.com/thankyou.php?inx01=' .
$inx01);

and the you can use the value in $_GET['inx01']

Ken

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com