Passing variables under a submit button

Posted on 2006-05-14
Medium Priority
Last Modified: 2010-04-03
Hi All,
I want to pass two url variables that a user has selected from two dynamic drop-downs. I’ve achieved this through a link on a page before using the example.php?cat_variable=test syntax but don’t know where to put it under a submit button. The two url variables I have set up are Type_variable (which I need to take from the drop-down named “Brand”) and the cat_variable (to be taken from “Category”) Any help would be much appreciated. Here’s the code to the page so far.

<?php require_once('../Connections/GSM_mobile.php'); ?>
mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_rsCatMod = "SELECT category_table.cat_category_id, category_table.cat_category_name, type_table.type_type_id, type_table.type_type_name, type_table.type_category_id FROM category_table, type_table WHERE category_table.cat_category_id = type_table.type_category_id";
$rsCatMod = mysql_query($query_rsCatMod, $GSM_mobile) or die(mysql_error());
$row_rsCatMod = mysql_fetch_assoc($rsCatMod);
$totalRows_rsCatMod = mysql_num_rows($rsCatMod);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<form id="type_cat_post" name="type_cat_post" method="post" action="">
  <p>Select Your Model Category and Type:</p>
    <select name="Category" id="Category" onchange="TCN_reload(this)">
      <option selected="selected">Category</option>
    <select name="Brand" id="Brand" onchange="TCN_reload(this)">
      <option selected="selected">Brand</option>
    <script language="JavaScript" type="text/javascript">
TCN_contents=new Array();
TCN_tempArray=new Array();
function TCN_addContent(str){
function TCN_split(){
      TCN_arrayValues = new Array();
function TCN_makeSelValueGroup(){
      TCN_selValueGroup=new Array();
      var args=TCN_makeSelValueGroup.arguments;
            TCN_tempArray[i]=new Array();
function TCN_makeComboGroup(){
      TCN_comboGroup=new Array();
      var args=TCN_makeComboGroup.arguments;
      for(i=0;i<args.length;i++) TCN_comboGroup[i]=findObj(args[i]);
function TCN_setDefault(){
      for (i=TCN_selValueGroup.length-1;i>=0;i--){
                                    if(TCN_selValueGroup[k]=="") TCN_selValueGroup[k]=TCN_arrayValues[j][(k*2)+1];
function TCN_loadMenu(daIndex){
      var selectionMade=false;
                  if(daArray[i][(daIndex*2)+1]==TCN_comboGroup[daIndex].options[j].value) existe=true;
                  TCN_comboGroup[daIndex].options[TCN_comboGroup[daIndex].options.length]=new Option(daArray[i][daIndex*2],daArray[i][(daIndex*2)+1]);
      if(selectionMade==false) TCN_comboGroup[daIndex].options[0].selected=true;
function TCN_reload(from){
            for(j=0; j<TCN_comboGroup.length; j++){
                  if(TCN_comboGroup[j]==from) index=j+1;
                                    if(TCN_comboGroup[index-1].options[i].value==TCN_tempArray[index-1][j][(index*2)-1]) TCN_tempArray[index][TCN_tempArray[index].length]=TCN_tempArray[index-1][j];
function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
 var separator="+#+";
<?php do{?>
TCN_addContent("<?php echo $row_rsCatMod['cat_category_name']; ?>+#+<?php echo $row_rsCatMod['cat_category_id']; ?>+#+<?php echo $row_rsCatMod['type_type_name']; ?>+#+<?php echo $row_rsCatMod['type_type_id']; ?>");
<?php } while ($row_rsCatMod = mysql_fetch_assoc($rsCatMod)); ?>

    <input type="submit" name="Submit" value="Select" />

Question by:dereksheahan
  • 4
  • 3
  • 2

Assisted Solution

siva350 earned 600 total points
ID: 16679478
Why not use the variables as form data insted? Or you could submit your form to the current page with a url variable used to setup an if ststement containing a redirect with all your variables plugged in to the url string.
LVL 70

Accepted Solution

Jason C. Levine earned 1200 total points
ID: 16679505
Hi Derek,

Here is the problem:

<form id="type_cat_post" name="type_cat_post" method="post" action="">

You have no action defined for this form.  If you send the form to this page or another PHP pages, all form variables become part of the $_POST array and you can then process them using this syntax (you've seen this before):


So in this case you have:

$_POST['Brand'] and $_POST['Category']

So the only question is -- what do you want this form to do?
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16679508
If you want those two variables to appear in the query string on another page, change the form to:

<form id="type_cat_post" name="type_cat_post" method="GET action="resultpage.php">

The URL for resultpage.php would then be:

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Author Comment

ID: 16682247
Hi Jason,
Great that works. One thing is confusing me however. Why I am using the "GET" action to post to another page?? Also, Is it possible to hide the results of passing url variables in the address bar?
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16684480
GET and POST work a little differently.  GET sends the form variables through the URL and redisplays them there as the query string, POST reads them into an array on the server.  In your orginial question, you mentioned passing the variables through the URL, so I showed you how to do that.

If you just want the variables available on the next page, change the form method to POST and call the variables out the the array per my original post.

Author Comment

ID: 16686411
Thanks for clearing that up. Is it possible to hide the variables being passed using the GET method though, or is that a silly question ? :)

Expert Comment

ID: 16686652
Post is the way I would do it, Jason seems to have it covered.
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16686861
Thanks siva...your first answer was right too, so Derek should give you an assist (hint hint, Derek.)

You can't hide the query string completely but if you want to protect information and still use GET, you can encrypt it.  Let's say you want to send an email to all of your customers and refer them back to your site to get a special or something.  Let us further say that you want to customize the web page for each customer.  The way you do this is to put the customer_id in the query string of the url:


But you shouldn't do that.  Why?  Because the user can sit there and alter the query string to pull up another customer's record and divulge private information.  So instead, you run some kind of encoding function like crypt() or md5() to produce a random string like:


For transactions that begin and end on a web site, just do as siva says and use POST.  Life is much easier.

Author Comment

ID: 16689450
thanks, that encoding function looks like fun. Might try to use that somewhere in the future. Cheers guys

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question