problems with $_POST returning NULL values in php 4.4.2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RDizzle

    problems with $_POST returning NULL values in php 4.4.2

    okay. so all i am doing is changing a registration script that uses
    $_GET to a script that uses $_POST, but the validation script now
    returns NULL values for all posted vars.

    What's the deal?

    NOTE: when i use $_GET the script just works.

    Thanks in advance for helping a noob.

    script with the form:
    <?php
    // Connect to a session
    session_start( );
    ?>
    <form method="POST" action="reg_val idate.php">
    <h2>User Profile</h2>
    <?php

    // Show meaningful instructions for UPDATE or INSERT or errors
    if(empty($error s))
    {
    if (session_is_reg istered("loginU sername"))
    {
    echo "<p><b>Plea se update your profile below as
    needed:</b></p>";
    }
    else
    {
    echo "<p><b>Plea se fill in all details below to
    join.</b></p>";
    }
    }else{
    // Display error message to the user
    showMessage();
    }
    ?>
    <table>
    <col span="1" align="right">

    <tr><td>User Name:</td>
    <td><? echo fieldError("use rName", $errors); ?>
    <input type="text" name="userName"
    value="<? echo $formVars["userName"]; ?>"
    size=25></td>
    </tr>

    <tr><td>Real Name:</td>
    <td><? echo fieldError("rea lName", $errors); ?>
    <input type="text" name="realName"
    value="<? echo $formVars["realName"]; ?>"
    size=25></td>
    </tr>

    <tr><td>Sex:</td>
    <td><select name="title">
    <option <?php if ($formVars["sex"]=="M")
    echo "selected"; ?>>M
    <option <?php if ($formVars["sex"]=="F")
    echo "selected"; ?>>F
    </select><br></td>
    </tr>

    <tr><td>City: </td>
    <td><? echo fieldError("cit y", $errors); ?>
    <input type="text" name="city"
    value="<? echo $formVars["city"]; ?>"
    size=20></td>
    </tr>

    <tr><td>State :</td>
    <td><? echo fieldError("sta te", $errors); ?>
    <input type="text" name="state"
    value="<? echo $formVars["state"]; ?>"
    size=20></td>
    </tr>

    <tr><td>Zipcode :</td>
    <td><? echo fieldError("zip code", $errors); ?>
    <input type="text" name="zipcode"
    value="<? echo $formVars["zipcode"]; ?>"
    size=5></td>
    </tr>

    <tr><td>Country :</td>
    <td><? echo fieldError("cou ntry", $errors); ?>
    <input type="text" name="country"
    value="<? echo $formVars["country"]; ?>"
    size=5></td>
    </tr>

    <tr><td>Date of birth (dd/mm/yyyy): </td>
    <td><? echo fieldError("dob ", $errors); ?>
    <input type="text" name="dob"
    value="<? echo $formVars["dob"]; ?>"
    size=10></td>
    </tr>

    <?php
    // Only show the username/email and password
    // <inputwidgets to new users
    if (!session_is_re gistered("login Username"))
    {
    ? <tr><td>Email :</td>
    <td><? echo fieldError("ema il", $errors); ?>
    <input type="text" name="email"
    value="<? echo $formVars["email"]; ?>"
    size=50></td>
    </tr>

    <tr><td>Passwor d:</td>
    <td><? echo fieldError("log inPassword", $errors); ?>
    <input type="password" name="loginPass word"
    value="<? echo $formVars["loginPassw ord"]; ?>"
    size=8></td>
    </tr>

    <tr><td><img src="/captcha.php"></td>
    <td><? echo fieldError("log inCaptcha", $errors); ?>
    Type in the text from the image to the left<br/>
    <input type="text" name="loginCapt cha"
    value="" size=8></td>
    </tr>

    <?php
    }
    ?>
    <tr>
    <td><input type="submit" value="Submit"> </td>
    </tr>
    </table>
    </form>
    <?php
    foot();
    //prevent session hijacks by clearing sessions once
    informations is
    displayed
    // Clear the formVars so a future <formis blank
    session_unregis ter("formVars") ;
    session_unregis ter("errors");
    ?>

    validation snippet:
    (not including all the validation just the meat where the vars are
    being grabbed)

    <?php
    // Initialize a session
    session_start() ;

    // Register an error array - just in case!
    if (!session_is_re gistered("error s"))
    session_registe r("errors");

    // Clear any errors that might have been
    // found previously
    $errors = array();
    $formVars = array();

    // Set up a $formVars array with the POST variables
    // and register with the session.
    if (!session_is_re gistered("formV ars"))
    session_registe r("formVars") ;

    // TO DO remove $HTTP_GET_VARS and use all $_GET variables
    // TO DO use $_POST
    $formVars["userName"] = clean($_POST["userName"],50);
    $formVars["realName"] = clean($_POST["realName"], 50);
    $formVars["sex"] = clean($_POST["sex"], 50);
    $formVars["city"] = clean($_POST["city"], 50);
    $formVars["state"] = clean($_POST["state"], 50);
    $formVars["zipcode"] = clean($_POST["zipcode"], 50);
    $formVars["country"] = clean($_POST["country"], 50);
    $formVars["dob"] = clean($_POST["dob"], 50);
    $formVars["email"] = clean($_POST["email"], 50);
    $formVars["loginPassw ord"] = clean($_POST["loginPassw ord"], 50);
    $formVars["loginCaptc ha"] = clean($_POST["loginCaptc ha"], 50);

    ....
    ?>

  • RDizzle

    #2
    Re: problems with $_POST returning NULL values in php 4.4.2

    figured out a workaround for $_POST

    instead of calling $_POST while assigning to my session array
    $form_vars like this:
    $formVars["userName"] = clean($_POST["userName"],50);

    i call $_POST to a normal var $userName like this:
    $userName = $_POST["userName"];

    then do
    $formVars["userName"] = clean($userName ,50);

    however, this does not explain why
    $formVars["userName"] = clean($_GET["userName"],50);

    works when using get method while
    $formVars["userName"] = clean($_POST["userName"],50);

    doesn't when using post method.

    so flummoxed,
    raymond

    Comment

    Working...