passing non-literal values in hyperlinks
Posted: Wed Oct 11, 2006 10:03 pm
Hi all
I am trying to pass a non literal value with a hyperlink like so:
On another form which is the ACTION value of the first form I have the following script:
All goes well if I submit the first form ...and i get this:
However if I click on the 'Show Values' link which redirects to $PHP_SELF with parameters , I get this on the page:
...no values for username,email and dessert....same with the address bar
on the browser... no values for username,email and dessert
$myaction is literal on the hyperlink string and that is why is shows...but the hyperlink cant get the values of the variable names from the
input boxes and the checkboxes.
What can be wrong...seems variable management has to be demystified in php.
I posted similar code earlier entitled passing variables from one function to another....but i decided to start a new thread
because it seems the problem is something else...including nonliterals in hyperlinks (it seems...)
The code is a mini version of a larger script for a more serious program and I would greatly apprec your expertise and help!
Thanks for your help!
I am trying to pass a non literal value with a hyperlink like so:
Code: Select all
<?php
function showtable(){
echo "<form action=\"preferences.php\" method=\"post\">\n";
echo "Name: <input type=\"text\" name=\"username\" /><br />\n";
echo "Email: <input type=\"text\" name=\"email\" /><br />\n";
echo "What is your favorite dessert?\n";
echo "<input type=\"CHECKBOX\" name=\"dessert[]\" value=\"pie\">\n";
echo "<input type=\"CHECKBOX\" name=\"dessert[]\" value=\"muffins\">\n";
echo "<a href=\"dessert.php?myaction=showtable\">Show Table</a>\n";
echo "<a href=\"dessert.php?myaction=showvalues&username=$username&email=$email&dessert=$dessert\">Show Values</a>\n";
echo "<br>\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit me!\" />\n";
echo "</form>\n";
}
function showvalues($a,$b,$c){
echo $a;
echo $b;
echo $c;
}
echo "action is " . $myaction;
switch($myaction){
case "showtable":
showtable();
break;
case "showvalues":
showvalues($username,$email,$dessert);
break;
default:
showtable();
break;
}
?>On another form which is the ACTION value of the first form I have the following script:
Code: Select all
<?php
if (!is_array($_REQUEST['dessert']))echo "not an array object";
ECHO $_REQUEST[dessert];
echo "<br>";
echo $_REQUEST['dessert'][0];
echo $_REQUEST['dessert'][1];
?>Code: Select all
Array
piemuffinsCode: Select all
Action is showvalueson the browser... no values for username,email and dessert
Code: Select all
http://localhost/dessert.php?myaction=showvalues&username=&email=&dessert=$myaction is literal on the hyperlink string and that is why is shows...but the hyperlink cant get the values of the variable names from the
input boxes and the checkboxes.
What can be wrong...seems variable management has to be demystified in php.
I posted similar code earlier entitled passing variables from one function to another....but i decided to start a new thread
because it seems the problem is something else...including nonliterals in hyperlinks (it seems...)
The code is a mini version of a larger script for a more serious program and I would greatly apprec your expertise and help!
Thanks for your help!