View Full Version : transferring a variable to another page.
aleminio
07-08-2006, 09:25 AM
I have a variable in a page, after i make a SUBMIT a new page loads , but i need to use that variable from the previous page, how can i do that?
Vin0rz
07-08-2006, 10:27 AM
I have a variable in a page, after i make a SUBMIT a new page loads , but i need to use that variable from the previous page, how can i do that?
I assume you need the values from a form? That depends on the method attribute of the form. If the method is post, than you can find it in $_POST['form_field_name']. If the method is get, you can find it in $_GET['form_field_name'], and it is appended to the url as ?form_field_name=value .
You can also use this by just making a link like this:
http://yourdomain.net/index.php?var1=value1&var2=value2
aleminio
07-08-2006, 01:34 PM
it's not what i mean.
I have for example a page called a.php where i need to type a TeamName
and password, when i press submit it loads a page called b.php
if the password and team doesn't match, of course the scripts stops.
but if it does, the b.php page has another form.
when i submit, it goes to c.php, but at this page i need the teamname as a variable, which i typed at a.php.
even if i put b.php and c.php at the same page.
after i submit the second form, the variable from the previous forms disappear.
thunderhoster
07-08-2006, 02:12 PM
the easiest way to do that is to output an hidden field with the value you want.
<input type="hidden" name="TeamName" value="<?=$_POST['TeamName']?>" />
aleminio
07-08-2006, 04:23 PM
look, here is the code (just started working on it, but useless to keep writing untill i find out how to do that)
as you can see at the beginning i have a variable called
$name (from a form of another page)
at this page i have 3 forms. each of them need to use that variable.
I gave an example at the end with the 3rd form. the $name means
the one at the beginning of the page, but obviously it's already doesn't exist there because it's a different form.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body text=white>
<?php
include("config/db_config.php");
$conn = mysql_connect ($db_host, $db_user, $db_password);
$db_select = mysql_select_db("$db_name",$conn);
if (!$db_select){
die ("Could not select the database: <br />". mysql_error());
}
?>
<?php
if ($_POST['submit']) {
$name =$_POST['clan_table'];
$pass =$_POST['pass'];
$check = mysql_query("SELECT * FROM $clanstable WHERE name = '$name'");
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
echo "<br>WRONG INFORMATION !!!!!!";
}
else
{
?>
<table align="center" width=400><tr><td>
<form method="post" action="<?php echo $_SERVER[PHP_SELF];?>">
<br />
Old report password:
<br />
<input type="password" name="orpass" style="border: 1 solid" class="text" >
<br />
New report password:
<br />
<input type="password" name="rpass" style="border: 1 solid" class="text" >
<br />
<?php
print "<input type=\"Submit\" name=\"sub1\" value=\"FINISH\" style=\"border: 1 solid\" class=\"text\">";
?>
</form>
<br />
<br />
<form method="post" action="<?php echo $_SERVER[PHP_SELF];?>">
Old Global password:
<br />
<input type="password" name="ogpass" style="border: 1 solid" class="text" >
<br />
New Global password:
<input type="password" name="gpass" style="border: 1 solid" class="text" >
<br />
<?php
print "<input type=\"Submit\" name=\"sub2\" value=\"FINISH\" style=\"border: 1 solid\" class=\"text\">";
?>
</form>
</td><td width=30></td>
<td valign=top width=100>
<br>
<form method="post" action="<?php echo $_SERVER[PHP_SELF];?>">
New player:
<input type="text" name="newpp" style="border: 1 solid" class="text" >
<?php
print "<input type=\"Submit\" name=\"sub3\" value=\"ADD\" style=\"border: 1 solid\" class=\"text\">";
echo "<br><br>";
echo "player list:";
?>
</form>
</td>
</tr>
</table>
<?php
}
}
}
?>
<?php
if ($_POST['sub3']) {
$newpp= $_POST['newpp'];
$sql = "INSERT INTO $playerstabke (name, user) VALUES ('$name', '$newpp')";
mysql_query($sql, $conn);
?>
<center>
<font color= blue" size=5>
<br>
<?php
echo "$newpp";
?>
</font>
<?php echo " has been added";
}
?>
</center>
</body>
</html>
Vin0rz
07-08-2006, 07:38 PM
Coincidentally, I have yesterday been looking up something to do this, and I found this: http://www.zend.com/zend/spotlight/mimocsumissions.php
It's definitely useful to me, I hope it is to you too.
Fumigator
07-08-2006, 10:06 PM
Sounds like this is easily solved using session variables.
Initiate a session by putting a session_start() at the top of every page. When the first form is submitted, copy the $_POST variables to $_SESSION variables, and they'll be available to you from that point on.
aleminio
07-08-2006, 10:58 PM
Sounds like this is easily solved using session variables.
Initiate a session by putting a session_start() at the top of every page. When the first form is submitted, copy the $_POST variables to $_SESSION variables, and they'll be available to you from that point on.
when i start a session i get this message
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\webs\test\web4\edit2.php:15) in C:\webs\test\web4\edit2.php on line 28
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\webs\test\web4\edit2.php:15) in C:\webs\test\web4\edit2.php on line 28
Vin0rz
07-09-2006, 09:12 AM
That's because you have to use session_start() really on top of your scripts, even before any header() information is sent.
aleminio
07-09-2006, 11:51 AM
thanks, magically works now :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.