Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Trouble passing key and value between pages

$
0
0

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.


Viewing all articles
Browse latest Browse all 13200

Trending Articles