Solved

Passing a value from a switch

Posted on 2013-01-23
7
273 Views
Last Modified: 2013-01-23
I have a switch on my main page.  the value of the switch is "s".  This all works fine; however; I'm opening a .php file and I need to pass the value of "s" to another switch in the php file.  
I tried this...and it's not happening.  Help is appreciated.

This is what opens the php file.  It's a button on a form.
<form method="post" action="Final.php>

Open in new window



$s = mysql_real_escape_string($_GET['s']);
		
mysql_select_db('MyDB'); 
		
		switch($s)
			{
                                                     case "Place":
                                                     break;

Open in new window

0
Comment
Question by:DS928
  • 5
  • 2
7 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 38811521
In the form you need
<input type="hidden" name="s" id="s">

then set the value from javascript with:

document.getElementById('s').value=s;

Cd&
0
 

Author Comment

by:DS928
ID: 38811587
Thank you.  OK I got the first part.

<form method="post" action="Final.php"Doggie">
<input type="hidden" name="s" id="s">

Open in new window


But the second part, I'm a little shaky on.  Which page does this go on?  The main page or the page that I am calling?  And after the where is the how.  Sorry, I am very new to this and I appreciate your patience and help.  This is the PHP page.

<?php
$dbc = mysql_connect('','','')
or die('Error connecting to MySQL server.'); 
$s = mysql_real_escape_string($_GET['s']);
	
mysql_select_db('MyDB'); 
		
		switch(s)
			{
			case "Place":
				echo "Place";
			break;
			case "Cuisine":
				echo "Cuisine";
			break;
			
			case "City":
			
			break;
			
			case "State":
			
			break;
			
			case "ZipCode":
			
			break;
		}
?>

Open in new window


Actually, the value is not coming from the form.  Its coming from here on the main page.

$(document).ready(function() {
	$("input:image").click(function(evt) {
	evt.preventDefault();
	var s = setSearch( $(this).val() )
	var k = getKitty( $(this).val() )
	var p = getPig( $(this).val() )
	//var g = getGoat( $(this).val() )
	;})
	})

Open in new window

Then set with this switch on the main page.

function setSearch(s)
	{
		switch(s){
 			case "Place":
  				$(document).ready(function () {
				$.ajax({
				url: 'place_place.php',
				success: function (html) {
				$("#Doggie").html(html);
				},
				error: function () {
				}
				});
				});
				break;
 			case "Cuisine":

Open in new window


The button on the form merely opens the php page.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38811852
You've lost me.  I don't understand the indirect routing.  The action on the form goes to final.php using post.  If that is not where you are processing server side, then you need to send to the page where you do process it.  

The other thing is that in the php it looks like you are trying to get the value from the $_GET global array but the method on the form is post so you should be getting it from the $_POST global array.  

I don't know what it is you are trying to do, but most of the time form generation and processing for the form get done in the same php file so that it can post back to itself, and reduce complexity.

Cd&
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:DS928
ID: 38812386
I'll admit its confusing.  If you go to this link I think it would be clearer.

http://www.menuhead.net/Steelers/sections_demo.php

I have the 5 images accross the top.  Whichever is selected, that decides whats in the three listboxes.  I have to run a results page based on the three boxes.  However I have 5 different result pages that can run, depending on what value was selected "Place","Cuisine", etc.  So I am trying to put a switch on the result button or image so that the proper results query runs.  I hope this is clearer.  Thank you.
0
 

Author Comment

by:DS928
ID: 38812738
So I added a hidden field to my form.  All I need to do now is this.  The name of the hidden field is "Glass".  When the user hits the submit button then....

Switch (Glass)
case "Place":
      open one.php
break;
case "Cuisine":
    open two.php
break;
case "City":
   open three.php
break;
case "State":
   open four.php
case "Zip":
    open five.php
break;

Open in new window

Just kind of air coding it, but I hope this explains it.
0
 

Author Comment

by:DS928
ID: 38812833
Have it figured out.  I put this in the form.....

<form onsubmit="return doSomething();">

Open in new window


and this in javascript....
function doSomething() {
    var g = $("#Glass").val();
alert("Hello");	
switch(g)
	{
}
return false;
}

Open in new window


This brings up the value that I needed from the form.  Thank you for your help.
0
 

Author Closing Comment

by:DS928
ID: 38812834
Pointed me in the right direction.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 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