Solved

Passing a value from a switch

Posted on 2013-01-23
7
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

630 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