...

View Full Version : passing values between pages



sesc
08-30-2007, 05:25 PM
I have three pages.
one.php
<form action="second.php" method="post">
<input type="text" name="txt">
<input type="submit" value="submit">
</form>

second.php
<?php
$err = $_Post['txt']; // from one.php

if($err == 1)
{
$errVal = 1; ?>
<script>
location.href = "third.php"
</script>

<?php }
else
{
echo $errVal;
}

?>


third.php
<?php
echo $errVal; // from second.php
?>

if the text value from one.php is 1, then automatically that should be redirected to third.php and should carry the variable ($errVal) value to third.php from second.php. How can I achieve this. I am new to this php!. Thanks in advance.

Mwnciau
08-30-2007, 05:34 PM
You can use the GET method, which allows you to carry variables in URLs:

one.php

<form action="second.php" method="post">
<input type="text" name="txt">
<input type="submit" value="submit">
</form>

second.php

<?php
$err = $_Post['txt']; // from one.php

if($err == 1)
{
$errVal = 1;
header('Location: third.php?err=1'); // This will be transfered to third.php
}
else
{
echo $errVal;
}

?>


third.php

<?php
echo $_GET['err']; // $_GET holds all URL variables
?>

This (http://www.w3schools.com/php/php_get.asp) explains it better.

sesc
08-30-2007, 05:39 PM
Thank you very much. This is working fine for me!

rafiki
08-31-2007, 12:15 AM
you could use php sessions... then you can use it on any page aslong as session_start() is at the top of the page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum