Page 1 of 1

passing non-literal values in hyperlinks

Posted: Wed Oct 11, 2006 10:03 pm
by kalikaye
Hi all


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];
?>
All goes well if I submit the first form ...and i get this:

Code: Select all

Array
piemuffins
However if I click on the 'Show Values' link which redirects to $PHP_SELF with parameters , I get this on the page:

Code: Select all

Action is showvalues
...no values for username,email and dessert....same with the address bar
on 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!

Re: passing non-literal values in hyperlinks

Posted: Thu Oct 12, 2006 12:42 am
by Christopher
There are a bunch of different problems with this code, from not passing $username,$email,$dessert t o showtables(), to mixing links and forms, to not receiving the values properly from the request. Plus I am not quite sure what "nonliterals" means. What is the one specific thing in the code above that is the biggest problem?