Jump to content

Trouble passing key and value between pages


lynwode
Go to solution Solved by requinix,

Recommended Posts

Howdy Folks,

I have a HTML form with a drop down box that has a key pair value behind it eg:

 

Key     Value

1         Widget1

2         Widget2

3         Widget3

.....

 

What I want to do is pass both the key and the value to the next page so I can use the key to query the DB  (the key is the pk from the DB) and the value for display purposes.

 

Currently I have two test scripts, the first creates the drop down and passes the parameters to the second which just displays them on a page:

<?php
 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
 echo "<html>";
 echo "<head>";
 echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">";
  echo "<title>Test Page</title>";
 echo "</head>";
  
 //Clear Form
 
 echo "<body>";
 $array = array();
 echo"<form action=\"test1.php\" method=\"post\">";
 echo "Year"."<select name=Year>";
 echo "<option>--Year--</option>";
 echo"<option value=\"1\">2008</option>";
 echo"<option value=\"2\">2009</option>";
 echo"<option value=\"3\">2010</option>";
 echo"<option value=\"4\">2011</option>";
 echo"</select>";
 
 echo "<input type=\"hidden\" name=\"Year_Dim\" value=\"Year_Dim\">";
  
 echo "<BR><input type=\"submit\" value=\"Submit\" /><br/>";
 
 echo "</form>"; 
 echo "</body>";
 echo "</html>";
 
?>

and

<?php
  print_r($_POST); 
  
 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
 echo "<html>";
 echo "<head>";
 echo "<title>Test Page</title>";
 echo "</head>";
 echo "<BR>";  
 echo "The Report was run with the following parameters. <BR><BR>";
	
 if (isset ($_POST[Year_Dim])) {
 	echo "Year: <B>".$_POST[Year]."</B><BR>";
	};
		
 echo "</body>";
echo "</html>"; 
?>

I have tried to pass both key and value but can't seem to get anywhere - its either one or the other. 

 

Does anyone have any pointers or examples that would guide me in the right direction.

 

Any help is greatly appreciated.

 

Cheers,

Tim.

Link to comment
Share on other sites

Good point - didn't think of that..... sometimes the blindingly obvious is our of site !

In this scenario this will work (with some SQL tweaking).

If there is a scenario (can't think of one right now) where this isn't feasible is there a way of passing both key and value.

 

Thanks for your help !

Link to comment
Share on other sites

Kinda, but if you're able to get the key and value at the same time anyways then you should be able to get them again on the next page.

 

[edit] You could pass both like "key,value" as the value, but you're still stuck validating it which requires getting the list of keys and values again anyways.

Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.