472,138 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,138 software developers and data experts.

i am trying to setup a link in my page that will change my page

I am working on a page with a right column that I want to use for
navigation. In this right column I am using the below code to set a
value for the link. I am using the variable $test right now.
I want to click on the link and when the value is set to a certain
value, say 1, I want the script to run and load a page based on a
switch case. This way I can use different links for navigation that
will load different forms and areas of my application. So here is the
code for the link line.

printf("<a href=\"%s?test=%s\">%s</a><br>\n", $_SERVER['PHP_SELF'],"1",
"Click Here");

I then want a switch statement to the effect

switch($test) {
case "1" :
Load form1
case "2" :
Load form2
case "3" :
Load form3;
}

To test out my idea I wrote this little test script to see if I could
get the response I wanted and it didn't work. I wanted to click on the
link and then get the value of test to echo back at me on the page.
Here is that code. I called the file testlink.php

<?php

printf("<a href=\"%s?test=%s\">%s</a><br>\n", $_SERVER['PHP_SELF'],"1",
"Click Here");

if (isset($test)){
echo "$test</br>\n";
}
?>
I get the right info in my url in my browser,

http://localhost/testlink.php?test=1

But I don't get the echo on the screen. Can anyone help?

May 17 '06 #1
2 1679
rich wrote:
I am working on a page with a right column that I want to use for
navigation. In this right column I am using the below code to set a
value for the link. I am using the variable $test right now.
I want to click on the link and when the value is set to a certain
value, say 1, I want the script to run and load a page based on a
switch case. This way I can use different links for navigation that
will load different forms and areas of my application. So here is the
code for the link line.

printf("<a href=\"%s?test=%s\">%s</a><br>\n", $_SERVER['PHP_SELF'],"1",
"Click Here");

I then want a switch statement to the effect

switch($test) {
case "1" :
Load form1
case "2" :
Load form2
case "3" :
Load form3;
}

To test out my idea I wrote this little test script to see if I could
get the response I wanted and it didn't work. I wanted to click on the
link and then get the value of test to echo back at me on the page.
Here is that code. I called the file testlink.php

<?php

printf("<a href=\"%s?test=%s\">%s</a><br>\n", $_SERVER['PHP_SELF'],"1",
"Click Here");

if (isset($test)){
echo "$test</br>\n";
}
?>
I get the right info in my url in my browser,

http://localhost/testlink.php?test=1

But I don't get the echo on the screen. Can anyone help?

$test = isset($_GET['test']) ? $_GET['test'] : null;

Add before you first use $test.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 17 '06 #2
Jerry thanks alot. I have been programming PHP for a month now and I
still forget little things. Here is the final code which worked of
course.

<?php
error_reporting(E_ALL ^ E_NOTICE);
$test =$_REQUEST['test'];

printf("<a href=\"%s?test=%s\">%s</a><br>\n", $_SERVER['PHP_SELF'],"1",
"Click Here");

if (isset($test)){
echo "$test</br>\n";
}
?>

May 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by JJ | last post: by
12 posts views Thread by Ron Weldy | last post: by
25 posts views Thread by Neo Geshel | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.