Solved

Passing a value from a switch

Posted on 2013-01-23
7
287 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

680 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