dereksheahan
asked on
Passing variables under a submit button
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=t est 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.
Thanks,
D
<?php require_once('../Connectio ns/GSM_mob ile.php'); ?>
<?php
mysql_select_db($database_ GSM_mobile , $GSM_mobile);
$query_rsCatMod = "SELECT category_table.cat_categor y_id, category_table.cat_categor y_name, type_table.type_type_id, type_table.type_type_name, type_table.type_category_i d FROM category_table, type_table WHERE category_table.cat_categor y_id = type_table.type_category_i d";
$rsCatMod = mysql_query($query_rsCatMo d, $GSM_mobile) or die(mysql_error());
$row_rsCatMod = mysql_fetch_assoc($rsCatMo d);
$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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="type_cat_post" name="type_cat_post" method="post" action="">
<p>Select Your Model Category and Type:</p>
<p>
<select name="Category" id="Category" onchange="TCN_reload(this) ">
<option selected="selected">Catego ry</option >
</select>
<select name="Brand" id="Brand" onchange="TCN_reload(this) ">
<option selected="selected">Brand< /option>
</select>
<script language="JavaScript" type="text/javascript">
TCN_contents=new Array();
TCN_tempArray=new Array();
TCN_counter=0;
function TCN_addContent(str){
TCN_contents[TCN_counter]= str;
TCN_counter++;
}
function TCN_split(){
TCN_arrayValues = new Array();
for(i=0;i<TCN_contents.len gth;i++){
TCN_arrayValues[i]=TCN_con tents[i].s plit(separ ator);
TCN_tempArray[0]=TCN_array Values;
}
}
function TCN_makeSelValueGroup(){
TCN_selValueGroup=new Array();
var args=TCN_makeSelValueGroup .arguments ;
for(i=0;i<args.length;i++) {
TCN_selValueGroup[i]=args[ i];
TCN_tempArray[i]=new Array();
}
}
function TCN_makeComboGroup(){
TCN_comboGroup=new Array();
var args=TCN_makeComboGroup.ar guments;
for(i=0;i<args.length;i++) TCN_comboGroup[i]=findObj( args[i]);
}
function TCN_setDefault(){
for (i=TCN_selValueGroup.lengt h-1;i>=0;i --){
if(TCN_selValueGroup[i]!=" "){
for(j=0;j<TCN_contents.len gth;j++){
if(TCN_arrayValues[j][(i*2 )+1]==TCN_ selValueGr oup[i]){
for(k=i;k>=0;k--){
if(TCN_selValueGroup[k]==" ") TCN_selValueGroup[k]=TCN_a rrayValues [j][(k*2)+ 1];
}
}
}
}
}
}
function TCN_loadMenu(daIndex){
var selectionMade=false;
daArray=TCN_tempArray[daIn dex];
TCN_comboGroup[daIndex].op tions.leng th=0;
for(i=0;i<daArray.length;i ++){
existe=false;
for(j=0;j<TCN_comboGroup[d aIndex].op tions.leng th;j++){
if(daArray[i][(daIndex*2)+ 1]==TCN_co mboGroup[d aIndex].op tions[j].v alue) existe=true;
}
if(existe==false){
lastValue=TCN_comboGroup[d aIndex].op tions.leng th;
TCN_comboGroup[daIndex].op tions[TCN_ comboGroup [daIndex]. options.le ngth]=new Option(daArray[i][daIndex* 2],daArray [i][(daInd ex*2)+1]);
if(TCN_selValueGroup[daInd ex]==TCN_c omboGroup[ daIndex].o ptions[las tValue].va lue){
TCN_comboGroup[daIndex].op tions[last Value].sel ected=true ;
selectionMade=true;
}
}
}
if(selectionMade==false) TCN_comboGroup[daIndex].op tions[0].s elected=tr ue;
}
function TCN_reload(from){
if(!from){
TCN_split();
TCN_setDefault();
TCN_loadMenu(0);
TCN_reload(TCN_comboGroup[ 0]);
}else{
for(j=0; j<TCN_comboGroup.length; j++){
if(TCN_comboGroup[j]==from ) index=j+1;
}
if(index<TCN_comboGroup.le ngth){
TCN_tempArray[index].lengt h=0;
for(i=0;i<TCN_comboGroup[i ndex-1].op tions.leng th;i++){
if(TCN_comboGroup[index-1] .options[i ].selected ==true){
for(j=0;j<TCN_tempArray[in dex-1].len gth;j++){
if(TCN_comboGroup[index-1] .options[i ].value==T CN_tempArr ay[index-1 ][j][(inde x*2)-1]) TCN_tempArray[index][TCN_t empArray[i ndex].leng th]=TCN_te mpArray[in dex-1][j];
}
}
}
TCN_loadMenu(index);
TCN_reload(TCN_comboGroup[ index]);
}
}
}
function findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&p arent.fram es.length) {
d=parent.frames[n.substrin g(p+1)].do cument; 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.len gth;i++) x=findObj(n,d.layers[i].do cument);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
TCN_makeSelValueGroup(""," ");
TCN_makeComboGroup("Catego ry","Brand ");
var separator="+#+";
<?php do{?>
TCN_addContent("<?php echo $row_rsCatMod['cat_categor y_name']; ?>+#+<?php echo $row_rsCatMod['cat_categor y_id']; ?>+#+<?php echo $row_rsCatMod['type_type_n ame']; ?>+#+<?php echo $row_rsCatMod['type_type_i d']; ?>");
<?php } while ($row_rsCatMod = mysql_fetch_assoc($rsCatMo d)); ?>
TCN_reload();
</script>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Select" />
</label>
</p>
</form>
</body>
</html>
<?php
mysql_free_result($rsCatMo d);
?>
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=t
Thanks,
D
<?php require_once('../Connectio
<?php
mysql_select_db($database_
$query_rsCatMod = "SELECT category_table.cat_categor
$rsCatMod = mysql_query($query_rsCatMo
$row_rsCatMod = mysql_fetch_assoc($rsCatMo
$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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="type_cat_post" name="type_cat_post" method="post" action="">
<p>Select Your Model Category and Type:</p>
<p>
<select name="Category" id="Category" onchange="TCN_reload(this)
<option selected="selected">Catego
</select>
<select name="Brand" id="Brand" onchange="TCN_reload(this)
<option selected="selected">Brand<
</select>
<script language="JavaScript" type="text/javascript">
TCN_contents=new Array();
TCN_tempArray=new Array();
TCN_counter=0;
function TCN_addContent(str){
TCN_contents[TCN_counter]=
TCN_counter++;
}
function TCN_split(){
TCN_arrayValues = new Array();
for(i=0;i<TCN_contents.len
TCN_arrayValues[i]=TCN_con
TCN_tempArray[0]=TCN_array
}
}
function TCN_makeSelValueGroup(){
TCN_selValueGroup=new Array();
var args=TCN_makeSelValueGroup
for(i=0;i<args.length;i++)
TCN_selValueGroup[i]=args[
TCN_tempArray[i]=new Array();
}
}
function TCN_makeComboGroup(){
TCN_comboGroup=new Array();
var args=TCN_makeComboGroup.ar
for(i=0;i<args.length;i++)
}
function TCN_setDefault(){
for (i=TCN_selValueGroup.lengt
if(TCN_selValueGroup[i]!="
for(j=0;j<TCN_contents.len
if(TCN_arrayValues[j][(i*2
for(k=i;k>=0;k--){
if(TCN_selValueGroup[k]=="
}
}
}
}
}
}
function TCN_loadMenu(daIndex){
var selectionMade=false;
daArray=TCN_tempArray[daIn
TCN_comboGroup[daIndex].op
for(i=0;i<daArray.length;i
existe=false;
for(j=0;j<TCN_comboGroup[d
if(daArray[i][(daIndex*2)+
}
if(existe==false){
lastValue=TCN_comboGroup[d
TCN_comboGroup[daIndex].op
if(TCN_selValueGroup[daInd
TCN_comboGroup[daIndex].op
selectionMade=true;
}
}
}
if(selectionMade==false) TCN_comboGroup[daIndex].op
}
function TCN_reload(from){
if(!from){
TCN_split();
TCN_setDefault();
TCN_loadMenu(0);
TCN_reload(TCN_comboGroup[
}else{
for(j=0; j<TCN_comboGroup.length; j++){
if(TCN_comboGroup[j]==from
}
if(index<TCN_comboGroup.le
TCN_tempArray[index].lengt
for(i=0;i<TCN_comboGroup[i
if(TCN_comboGroup[index-1]
for(j=0;j<TCN_tempArray[in
if(TCN_comboGroup[index-1]
}
}
}
TCN_loadMenu(index);
TCN_reload(TCN_comboGroup[
}
}
}
function findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&p
d=parent.frames[n.substrin
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;
for(i=0;!x&&d.layers&&i<d.
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
TCN_makeSelValueGroup("","
TCN_makeComboGroup("Catego
var separator="+#+";
<?php do{?>
TCN_addContent("<?php echo $row_rsCatMod['cat_categor
<?php } while ($row_rsCatMod = mysql_fetch_assoc($rsCatMo
TCN_reload();
</script>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Select" />
</label>
</p>
</form>
</body>
</html>
<?php
mysql_free_result($rsCatMo
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
Thanks,
D
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?
Thanks,
D
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.
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.
ASKER
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 ? :)
Post is the way I would do it, Jason seems to have it covered.
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:
www.example.com/offer.php?customer_id=1
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:
www.example.com/offer.php?cistomer_id=c4ca4238a0b923820dcc
For transactions that begin and end on a web site, just do as siva says and use POST. Life is much easier.
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:
www.example.com/offer.php?customer_id=1
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:
www.example.com/offer.php?cistomer_id=c4ca4238a0b923820dcc
For transactions that begin and end on a web site, just do as siva says and use POST. Life is much easier.
ASKER
thanks, that encoding function looks like fun. Might try to use that somewhere in the future. Cheers guys
<form id="type_cat_post" name="type_cat_post" method="GET action="resultpage.php">
The URL for resultpage.php would then be:
http://www.derektestsite.com/resultpage.php?Brand=selection1&Category=selection2