Solved

Passing a value from a switch

Posted on 2013-01-23
7
254 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:DS928
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Pointed me in the right direction.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now