passing vars from page to page

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

david_ste
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Mar 18, 2003 4:43 am

passing vars from page to page

Postby david_ste » Tue Mar 18, 2003 4:56 am

This is the first time I have ever attempted to use .php so please excuse my ignorance. What I want to do is to pull in a variable from a query string, then pass it on to another page by adding it to the next url.

I know that in .asp I would usually write

<%
level = request.querystring("level")
%>

then write out the url as

<html>
<body

http://www.someserver/somepage/?level=<%=level%>

</body>
</html>

I would be grateful if anyone could help me write out this in .php.

Thank you for any help in advance. :?

User avatar
Skeletor
New php-forum User
New php-forum User
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio
Contact:

Postby Skeletor » Tue Mar 18, 2003 5:08 am

Something like this should work:

<a href="http://www.someserver/somepage/<?php print(!empty($_REQUEST['level']) ? '?level='.$_REQUEST['level'] : ''); ?>">link name</a>

you can retrieve the level passed from another page by using one of the following:
$_REQUEST['level']
$_POST['level']
$_GET['level']

You can then add this variable to your link by printing it where it needs to go. The above example tests to make sure the level is not empty, if it is, it will append an empty string to the url. If it is not empty, it will add a '?' and the level variable to the url.

The syntax of:
(test) ? (something) : (something else)
is just short hand for the if-then-else.

david_ste
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Mar 18, 2003 4:43 am

Postby david_ste » Tue Mar 18, 2003 5:11 am

Thank you very much for your help. Castle Grey Skull would be proud of you Skelator

Romantik
New php-forum User
New php-forum User
Posts: 67
Joined: Mon Feb 24, 2003 2:55 am
Location: ../Ukraine/Kherson
Contact:

Postby Romantik » Tue Mar 18, 2003 5:18 am

Code: Select all

<?php
$level= $_GET["level"];
?>


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest