|
Subject:
|
request values into variable from another form ?
|
|
Posted By:
|
rehana
|
Post Date:
|
12/15/2003 4:49:47 PM
|
hi everyone, I need the syntax to request the values stored in variables of another form. example in asp we can do it in the following way as in the example given below. how do we do it in php?
mixed $comDate mixed $comName comDate = Request.Form("hdndate") //correction needed here comName = Request.Form("hdnComName") thanks, rehana.
|
|
Reply By:
|
nikolai
|
Reply Date:
|
12/15/2003 5:23:02 PM
|
As Rich has mentioned in your other related threads*, you don't need to explicitly declare a variable or it's type.
$my_var = "Hello, world."; // $my_var is a string. $my_var = 62; // $my_var is now an integer. $my_var = $my_var * 5.2; // $my_var is now a float. $my_var['idx'] = 'Wow'; // $my_var is now an array.
etc...
* Related threads: http://p2p.wrox.com/topic.asp?TOPIC_ID=7613 http://p2p.wrox.com/topic.asp?TOPIC_ID=7615 http://p2p.wrox.com/topic.asp?TOPIC_ID=7616
Take care,
Nik http://www.bigaction.org/
|
|
Reply By:
|
nikolai
|
Reply Date:
|
12/15/2003 5:24:51 PM
|
In PHP, you don't need to declare variables to store the values submitted by a form. They are accessed via the $_GET or $_POST arrays, depending on the form method. For example:
echo "You submitted " . $_POST['hdndate'];
If you want to copy the value of a submitted variable into another variable, that's just making a regular assignment statement -- nothing special.
$comDate = $_POST['hdndate']; $comName = $_POST['hdnComName'];
Take care,
Nik http://www.bigaction.org/
|
|
Reply By:
|
pi
|
Reply Date:
|
12/15/2003 9:31:46 PM
|
This discussion seems to be on the boundary of the question that I was wondering about. Let's say I have a web page with some script 1.php that contains a variable $text. $text is a string with many funny charecters like spaces \n etc. Let's also say that script 1.php launches another page 2.php that also has to use information in the $text variable. What would be the recommended way to pass the variable $text from script 1.php to script 2.php? thanks, pi
|
|
Reply By:
|
nikolai
|
Reply Date:
|
12/16/2003 11:35:27 AM
|
How exactly does it "launch" this other page? If all you do is include the second page, then all the variables and functions in scope when you call include() in script1.php are available in script2.php.
Example:
<?php /* script2.php */ echo $text; ?>
<?php /* script1.php */ $text = 'lots of text.';
include('script2.php');
?>
This will print 'lots of text.' to the client.
If your two scripts are being executed as part of two different pages, then store the variables you want to persist across requests in a session variable.
<?php /* script1.php */ session_start(); $_SESSION['text'] = 'some text.';
echo '<a href="script2.php">click here</a>\n"; ?>
( user clicks the link )
<?php /* script2.php */ session_start();
echo $_SESSION['text']; ?>
This will print 'some text.' to the client.
Take care,
Nik http://www.bigaction.org/
|
|
Reply By:
|
pi
|
Reply Date:
|
12/16/2003 1:34:12 PM
|
Thank you Nik! This gives me enough material to start digging in the manual. From what I see about include() there, I think I meant the second approach that you suggested. As you can tell, I am just starting with this. Thanks, pi
|