Solved

Get A Variable

Posted on 2009-06-29
5
172 Views
Last Modified: 2013-11-05
Why can't I get this to work?  
This is a database of veteran's information.  In one table we store all the wars that veterans might have been involved in.  We then build a form that provides a drop down to select a war.  That works fine.  The problem is that when they click SUBMIT, I am not getting the name of the war in the next script.  Any ideas?  Here's the code:


<td width="50%">&nbsp;By Battle/Campaign</td>
	          <td width="50%">&nbsp;By Last Name</td>
		    </tr>
	        <tr></td>
			   <form name="srchid" method="POST" action="admin_veteran_2.php" onsubmit="return submitform('srchid2', 0);">
		      
<td width="15%" class="tdinput">
                  <select size="1" name="srchid2">
				   <?
				   //Display Generations from table
				   foreach($schools as $school){
				   ?>
                    <option value="<? echo $school->ID; ?>"><? echo $school->War; ?></option>
				   <?
				   };
				   ?>
                  </select>
                  <input type="submit" value="srchid2" name="submit" class="frmbut">
                  <input type="hidden" name="action" value="srchid">
	          </td>
			  </form>

Open in new window

0
Comment
Question by:dougp23
[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
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24738176
The code you posted seems ok, maybe the error is in admin_veteran_2.php. How do you fetch the submitted variable?
0
 
LVL 1

Author Comment

by:dougp23
ID: 24739284
In admin_veteran_2.php, I have this:
(The first chunk is the function get_param and then the next line is where I try to grab the paramter).  I guess my issue is, I'm not sure WHERE I am storing the parameter from the SELECT.

If I echo $whatis I get nothing.
function get_param($param_name)
{
  global $HTTP_POST_VARS;
  global $HTTP_GET_VARS;
 
  $param_value = "";
  if(isset($HTTP_POST_VARS[$param_name])) {
    $param_value = $HTTP_POST_VARS[$param_name];
  } else if(isset($HTTP_GET_VARS[$param_name])) {
    $param_value = $HTTP_GET_VARS[$param_name];
  }
  return $param_value;
}
 
$whatis=get_param("$srchid2");

Open in new window

0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 250 total points
ID: 24739829
First, the call to get_param() should be like this, without the $ character:

$whatis=get_param("srchid2");

Second, $HTTP_POST_VARS and $HTTP_GET_VARS are deprecated, and not supported on all servers. Do like this instead, this will fetch both POST and GET variables:

$whatis=isset($_REQUEST['srchid2'])?$_REQUEST['srchid2']:'';
0
 
LVL 1

Author Closing Comment

by:dougp23
ID: 31598020
Well that worked!  I guess I must be on a server where those functions are deprecated.  Now I need to do some real digging since I have quite a few PHP apps where I used that function (get_param).  Hopefully they replaced the other calls with something else after deprecating them.
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24745238
>> Hopefully they replaced the other calls with something else after deprecating them.

$HTTP_POST_VARS is replaced by $_POST and $HTTP_GET_VARS is replaced by $_GET, both are "superglobals", which means they are automatically available within functions without using the "global" keyword.

http://php.net/manual/en/reserved.variables.php
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 …

730 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