Variable wont echo

Posted by jonnnnnnnnnie on Stack Overflow See other posts from Stack Overflow or by jonnnnnnnnnie
Published on 2010-12-25T04:27:55Z Indexed on 2010/12/25 4:54 UTC
Read the original article Hit count: 154

Filed under:
|

I have the following code, where the var $username doesn't echo, when you type in a value.

//TODO: SET AUTH TOKEN as random hash, save in session
$auth_token =  rand();   

if (isset($_POST['action']) && $_POST['action'] == 'Login')
{

    $errors = array(); //USED TO BUILD UP ARRAY OF ERRORS WHICH ARE THEN ECHOED
    $username = $_POST['username'];

    if ($username = '')
    {
        $errors['username'] = 'Username is required';
    }

    echo $username; // var_dump($username) returns string 0
}


require_once 'login_form.html.php';

 ?>

login_form is this:

<form method="POST" action="">
<input type="hidden" name="auth_token" value="<?php echo $auth_token ?>">
Username: <input type="text" name="username">
Password: <input type="password" name="password1">
<input type="submit" name="action" value="Login">
</form>

The auth token part isn't important, it just when I type in a value in username textbox and press the login button, the username wont echo, var_dump returns string (0) and print_r is just blank.

© Stack Overflow or respective owner

Related posts about php

Related posts about variables