Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 15th, 2003, 05:49 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default request values into variable from another form ?

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.

  #2 (permalink)  
Old December 15th, 2003, 06:23 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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/
  #3 (permalink)  
Old December 15th, 2003, 06:24 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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/
  #4 (permalink)  
Old December 15th, 2003, 10:31 PM
pi pi is offline
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #5 (permalink)  
Old December 16th, 2003, 12:35 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default


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/
  #6 (permalink)  
Old December 16th, 2003, 02:34 PM
pi pi is offline
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Request.Form / Request.QueryString Toran Classic ASP Databases 4 January 17th, 2007 02:23 PM
request.qurystring vs. request.form Durwood Edwards Classic ASP Databases 3 June 18th, 2004 12:09 AM
request.querystring() , request.form() alyeng2000 ASP.NET 1.0 and 1.1 Basics 1 December 30th, 2003 12:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.