pass variable from one page to another

Alles, was PHP betrifft, kann hier besprochen werden.

pass variable from one page to another

Postby asheesh » 07. November 2007 12:23

:arrow:
hi
how we pass a php variable to another page
for example we have $user = "asheesh"; in one page now we want to pass this $user to next page,i.e, action page .how this could be done?
asheesh
 
Posts: 8
Joined: 29. August 2007 07:37

Postby Scory » 07. November 2007 12:37

What means "next page"? Do you include a local script? Do you have a <form ..>, where the action=... is the "next page"? Is "next page" on same server, or on different server?

If the next page is on the same server, you may either use cookies or sessions to pass variables. If it is different server, you should add a form variable into the form with type="hidden", which contains the value of the variable (i.e. user name).

Example:

Code: Select all
<form action="...." method="POST">
<input type="hidden" name="username" value="<?=$user?>">
<input type="text" name="blabla">
...
</form>


Regards
Scory
Scory
 

Postby sari42 » 17. November 2007 11:14

to make sure that your script will also run on php installations where short_open_tag is off, use:
<?php echo $user; ?> instead of <?=$user?>
sari42
 
Posts: 800
Joined: 27. November 2005 18:28

Postby Scory » 17. November 2007 22:12

sari42 wrote:to make sure that your script will also run on php installations where short_open_tag is off, use:
<?php echo $user; ?> instead of <?=$user?>


This is not necessary, the special token "<?=" is working either for short or long php tag.

Greets
Scory
Scory
 

Postby Wiedmann » 18. November 2007 00:56

This is not necessary, the special token "<?=" is working either for short or long php tag.

http://de.php.net/manual/en/function.echo.php wrote:This short syntax only works with the short_open_tag configuration setting enabled.
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby Scory » 18. November 2007 16:10

Stimmt - ich hätte das jetzt anders erwartet, bei den Planungen für PHP 6 wurde nämlich darüber entschieden, zwar Short Tags gar nicht mehr zu erlauben, aber dennoch "<?=" als Kurzform für "<?php echo" zu belassen (was ich wichtig finde).

Etwas verwirrend, aber wichtig, denn genau so benutze ich es seit eh und je. Die Form "<?php echo ...?>" ist häßlich.

Grüße
Scory
Scory
 

Postby dlmaster » 15. December 2007 17:06

How can I retrive form values from page1 after I have submit the form in page2? I only manage to $_GET the values before submit... Is there a way to retrieve this as I hope that the user can fill in the second form before inserting all the values from both forms into database. Thanks in advance... :oops:
dlmaster
 
Posts: 19
Joined: 12. November 2007 05:54

Postby Wiedmann » 15. December 2007 17:38

How can I retrive form values from page1 after I have submit the form in page2?

Store the values from form/page1 in a session variable.
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby dlmaster » 15. December 2007 19:21

I pass the variables through url to the page2. So I have used $_GET to retrieve the value. I only have used the $_SESSION to pass array ... I am not sure on how to pass session variable to page2 ..
dlmaster
 
Posts: 19
Joined: 12. November 2007 05:54


Return to PHP

Who is online

Users browsing this forum: No registered users and 1 guest