Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2002

    Unanswered: requesting form variables

    i am using the following code to request firstname from a posted form:

    if ( $firstname == "dog" )
    { echo( "Hello!" );}
    { echo( "Welcome, $firstname!" );}

    but the variable $firstname is always empty, what am i doing wrong ?

    please help,


  2. #2
    Join Date
    Jun 2002
    What's your HTML look like? I would assume offhand (without seeing it) that you have a case sensitivity problem.

  3. #3
    Join Date
    Jul 2002
    try add this this:

    $firstname = $HTTP_GET_VARS["firstname"];


    $firstname = $HTTP_POST_VARS["firstname"];

    if your method in form is POST

    problem can be also if you use this in some funcition... in that case you need:

  4. #4
    Join Date
    Sep 2002
    you may be wrestling with a register_globals problem...

    when php is useing register_globals, it automatically maps anything 'posted' from a form or 'getted' from the url are mapped into variables of the name set.... as of the new versions of php this variable is turned off by default... register_globals also looks in may other places for variables including any cookies and the sessions and the environment....

    you may be interested in a function like this.... which mimicks the functionality of register globals, but acts on a variable by variable basis...

    * find a variable if it exists in specified location
    * looks in specified places, in specified order, to find the. return a default if not found in specified places.
    * $username = findVar('username','SP','guest');
    * the above statement means: look for the varible named username in the Session, then the form POST, if not found in either place then set username to 'guest'
    * @param $var_name - string, mandatory. The name of the variable to look for. ( for $var1 you send "var1" )
    * @param $order - string, optional, default:'ECSPG', restriction: arbitrarily ordered subset of 'ECSPG'.
    * The order of places to look for the variable. First Come First Serve.
    * NOTE: this works in opposite order as the register_globals setting as defined in your php.ini
    * 'ECSPG' = look first for variables set in the local scope, than as environmental varibles if found, return them
    * look for varibale in the cookie, if found there return it
    * look for variable in the session, if found there returnit
    * look for variable in the form POST, if found there return it
    * look for variable in the GET query, if found there return it
    * if not found yet, return whatever $default is set to
    * @param $default - mixed, optional, default:NULL. if not found anywhere with $order, set return this thing.
    * @return mixed, the found variable of $defualt.
    function findVar( $var_name, $order="ECSPG", $default=NULL )

    foreach ( range(0,(strlen($order)-1)) as $i ) {
    switch ( strtoupper($order{$i}) ) {
    case 'E':
    if ( isset($GLOBALS) && isset($GLOBALS[$var_name]) ) {
    return $GLOBALS[$var_name];
    } else if ( $result = getenv($var_name) ) {
    return $result;

    case 'C':
    if ( isset($_COOKIE) && isset($_COOKIE[$var_name]) ) {
    return $_COOKIE[$var_name];
    } else if ( isset($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS[$var_name]) ) {
    return $HTTP_COOKIE_VARS[$var_name];

    case 'S':
    if ( isset($_SESSION) && isset($_SESSION[$var_name]) ) {
    return $_SESSION[$var_name];
    } else if ( isset($HTTP_SESSION_VARS) && isset($HTTP_SESSION_VARS[$var_name]) ) {
    return $HTTP_SESSION_VARS[$var_name];

    case 'P':
    if ( isset($_POST) && isset($_POST[$var_name]) ) {
    return $_POST[$var_name];
    } else if ( isset($HTTP_POST_VARS) && isset($HTTP_POST_VARS[$var_name]) ) {
    return $HTTP_POST_VARS[$var_name];

    case 'G':
    if ( isset($_GET) && isset($_GET[$var_name]) ) {
    return $_GET[$var_name];
    } else if ( isset($HTTP_GET_VARS) && isset($HTTP_GET_VARS[$var_name]) ) {
    return $HTTP_GET_VARS[$var_name];


    return $default;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts