Solved

Passing a value from a switch

Posted on 2013-01-23
7
280 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

827 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