Advertisement

06.25.2004 at 10:02PM PDT, ID: 21038841
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Passing Parameter/Variable via URL

Tags: php, url, parameter, passing, variable
Hi there,

I'm testing on passing parameter via url with the three php files as shown below:
1. index.php
2. pg2.php
3. pg3.php

The index.php will allow user to input something and then pass the variables to pg2.php  to display.
In pg2.php, there is text url/link that will pass the variables to pg3.php and display again.

Problem: I could only pass the variables till pg2.php but not to pg3.php.

Here is the simple code that I have written:

Index.php
======
<html>
<head>
<title>Login</title>
</head>
<body onload=document.test.username.focus()>
<form method="POST" action="pg2.php" name="test">
Username: <input type="text" name="username" size="20">
Password: <input type="password" name="password" size="20"><br>
?>
<input type="submit" value="Submit" name="login">
</form>
</body>
</html>

----------------------------------------------------------------------------------------------------


pg2.php
=====

<html>
<head>
<title>Login</title>
</head>
<body>
<form action="pg3.php"  method="POST">

Username input: <?php echo $_POST['username']."<br>"; ?>
Password input: <?php echo $_POST['password']."<br><br>"; ?>
<a href="pg3.php?username=$_POST['username']">Go to Page 3</a>
</form>
</body>
</html>

----------------------------------------------------------------------------------------------------

pg3.php
=====
<html>
<head>
<title>Login</title>
</head>
<body>
<form method="POST">
This is page 3.<br><br>

<? php echo $_POST['username']; ?>

</form>
</body>
</html>

Please advise.


Thank you.
Start your free trial to view this solution
Question Stats
Zone: Web Development
Question Asked By: altric
Solution Provided By: Diablo84
Participating Experts: 5
Solution Grade: A
Views: 944
Translate:
Loading Advertisement...
06.25.2004 at 10:29PM PDT, ID: 11404188

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.25.2004 at 10:32PM PDT, ID: 11404192

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.26.2004 at 02:55AM PDT, ID: 11404783

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.26.2004 at 06:55PM PDT, ID: 11408209

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.26.2004 at 06:59PM PDT, ID: 11408229

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.26.2004 at 11:02PM PDT, ID: 11408815

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.26.2004 at 11:08PM PDT, ID: 11408830

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.26.2004 at 11:25PM PDT, ID: 11408868

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.27.2004 at 03:09AM PDT, ID: 11409248

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.27.2004 at 04:13AM PDT, ID: 11409337

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.27.2004 at 04:15AM PDT, ID: 11409340

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.27.2004 at 09:48AM PDT, ID: 11410672

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.27.2004 at 09:49AM PDT, ID: 11410674

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.27.2004 at 07:14PM PDT, ID: 11412455

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.27.2004 at 10:44PM PDT, ID: 11413183

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.02.2005 at 02:49PM PDT, ID: 14135045

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
06.25.2004 at 10:29PM PDT, ID: 11404188
In page 2 you are not using the form to pass the data, you using the hyperlink, so on page 3 just read the variable like this:

pg3.php
=====
<html>
<head>
<title>Login</title>
</head>

<form method="POST">
This is page 3.



<? php echo $username; ?>

</form>
</body>
</html>

If you want to keep sending the data with the form, then send the data from page 2 with the form, a link is not part of the form...

Hope this helps for you... ;)
 
06.25.2004 at 10:32PM PDT, ID: 11404192
On page 3, as the data is not sent via form, it can't be read on page 3 with $_POST['username'];

 $_POST[];
 $_GET[];

are for form variables...
 
06.26.2004 at 02:55AM PDT, ID: 11404783

Rank: Genius

you might be better off using sessions for what you are doing, here is an overview of how that would work

at the top of every page:

session_start();

to assign a variable to a session var:

$_SESSION['varname'] = $var;

for example: $_SESSION['username'] = $_POST['username'];

you can then use the session variables on any page by, for example:

echo $_SESSION['username'];

This means that you do not have to pass variables in the url query string, which will be more secure for starters. It also means you wont have to keep reassigning variables on every page that you want to pass the data through. The values of the session variables will remain all the time the session is active (ie. until the user closes their browser).
 
06.26.2004 at 06:55PM PDT, ID: 11408209
Thank you for the responses.

I have tried to modify the lines that you pointed out to me but when I click on the link on pg2.php, it shows:

"Parse error: parse error, unexpected T_ECHO in H:\MSC-Apache\xampp\htdocs\pg3.php on line 9"

Is it something with the code on pg2.php?

Please advise.

Thanks again.
 
06.26.2004 at 06:59PM PDT, ID: 11408229
Post your new code...
 
06.26.2004 at 11:02PM PDT, ID: 11408815
Index.php
======
<html>
<head>
<title>Login</title>
</head>

<form method="POST" action="pg2.php" name="test">
Username:
Password:


</form>
</body>
</html>

------------------------------------------------------------------------


pg2.php
=====

<html>
<head>
<title>Login</title>
</head>

<form action="pg3.php"  method="POST">

Username input: <?php echo $_POST['username']."
"; ?>
Password input: <?php echo $_POST['password']."

"; ?>
Go to Page 3
</form>
</body>
</html>

------------------------------------------------------------------------

pg3.php
=====
<html>
<head>
<title>Login</title>
</head>

<form method="POST">
This is page 3.



<? php echo $username; ?>

</form>
</body>
</html>

Actually doesn't much difference, I just changed the line that you mentioned to me.

Thank you.

 
06.26.2004 at 11:08PM PDT, ID: 11408830
Page 2 should loke like this:

pg2.php
=====

<html>
<head>
<title>Login</title>
</head>

<form action="pg3.php"  method="POST">

Username input: <?php echo $_POST['username']."
"; ?>
Password input: <?php echo $_POST['password']."

"; ?>
">Go to Page 3
</form>
</body>
</html>

Since the value you are giving to the href is a PHP variable you need to print it in PHP environment... ;)

That should do it...
Assisted Solution
 
06.26.2004 at 11:25PM PDT, ID: 11408868
Page 3 has a bug as well

Should look like this:

<html>
<head>
<title>Login</title>
</head>

<form method="POST">
This is page 3.



<?php echo $username; ?>

</form>
</body>
</html>

In the line <?php echo ""; ?> you can't have a space between the <? and php like you have...
Assisted Solution
 
06.27.2004 at 03:09AM PDT, ID: 11409248

Rank: Genius

altric, I still think you would be better off using sessions so here is a quick session solution if ever you decide to go this way

Index.php
======
<?php
session_start();
?>

<html>
<head>
<title>Login</title>
</head>

<form method="POST" action="pg2.php" name="test">
Username:
Password:

?>

</form>
</body>
</html>

----------------------------------------------------------------------------------------------------


pg2.php
=====
<?php
session_start();
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
?>

<html>
<head>
<title>Login</title>
</head>

<form action="pg3.php"  method="POST">

Username input: <?php echo $_SESSION['username']."
"; ?>
Password input: <?php echo $_SESSION['password']."

"; ?>
Go to Page 3
</form>
</body>
</html>

----------------------------------------------------------------------------------------------------

pg3.php
=====
<?php
session_start();
?>

<html>
<head>
<title>Login</title>
</head>

<form method="POST">
This is page 3.



<?php echo $_SESSION['username']; ?>

</form>
</body>
</html>
Accepted Solution
 
06.27.2004 at 04:13AM PDT, ID: 11409337
First, if you want to submit via the url-string, you have to use the GET method, not POST.

Second, on page two, you have to explicitly submit the form to pass the variable. Your link must include a command to submit the form, such as:

<a href="javascript:'onload="document.forms[0].submit;"'>Go to Page 3</a>

the form's action will successfully execute the link to pg3.php.


Assisted Solution
 
06.27.2004 at 04:15AM PDT, ID: 11409340
oops,

<a href="javascript:'onload="document.forms[0].submit;"'>Go to Page 3</a>
should read
<a href="javascript:"document.forms[0].submit;"'>Go to Page 3</a>

sorry
 
06.27.2004 at 09:48AM PDT, ID: 11410672

Rank: Genius

>> Second, on page two, you have to explicitly submit the form to pass the variable.

On the second page there is not actually any form fields to pass, the reason I did not remove them in the example i provided was because i presumed there was the possibility that altric will add form fields at a later time.

Further more, if form fields are added then you can presume that this will also include a submit button, using the sessions method this will not cause any problems or require much change to the code.

If altric wishes to continue to use the GET method its still possible, although much more inconvienient, as the query string can be added to the forms action.
 
06.27.2004 at 09:49AM PDT, ID: 11410674

Rank: Genius

"I did not remove them" - refering to the form tags
 
06.27.2004 at 07:14PM PDT, ID: 11412455
Thanks a lot for all your kind helping hands...

I appreaciate that.

Thank you very much.
 
06.27.2004 at 10:44PM PDT, ID: 11413183
diablo,

I agree session variables are more convenient, but the question said "in the url", so I assumed it was an exercise in passing variables via forms, not as session variables, so I was sticking with that method, which requires a submission of the form variables from page2 to page3. That was the error in the original submission.
 
06.02.2005 at 02:49PM PDT, ID: 14135045
extract($_REQUEST);
 
 
11.20.2007 at 02:04AM PST, ID: 20318592
I was having problems passing variables across what I will call multi-page sessions. The answer provided by Diablo84 helped me enormously.
 
 
 
20080236-EE-VQP-29