i have a login form. if there is a error. let say user doesnt fill input fields. than it will print error. but i want to keep the values safe. that way user dont have to keep fill in data again and again.

here i have a form. iam print the error. and than there are some input fields.
in side that

if(array_key_exists('log_error', $_SESSION) && !empty($_SESSION['log_error']))

i want to set user data back to fields.

<form  id='login' action='login.php' method='POST'>
<?php
                    //print errors
                   if(array_key_exists('log_error', $_SESSION) && !empty($_SESSION['log_error']))
                    {
                        $log_error_r = $_SESSION['log_error'];
                        echo "<span style='background-color:#D00000;'> $log_error_r <br/></span>";

                        unset($_SESSION['log_error']);
       }
    ?>
 <input type="text" name="username" id="login_username" class="login_field" value="" />
 <input type="password" name="password" id="login_password" class="login_field" value=""/>
 <input type="checkbox" name="remember" id="login_remember" value="yes" />
 <button type="submit">Log in</button> 
</form>

php file

<?php
    if($_SERVER['REQUEST_METHOD'] == 'POST') 
    {
        $username_p = $_POST['username'];
        $password_p = $_POST['password'];
        $log_error = "";
    echo"$password_p";  
        if($username_p && $password_p)
        {
            if(strlen($username_p) > 20 && strlen($password_p) > 20)
            {
                $log_error .= "Error - Username or Password too long!";
            }
            else
            {
            .....
            $_SESSION['log_error'] = $log_error;
            }
            ?>
Member Avatar for LastMitch

@hwoarang69

i have a login form. if there is a error. let say user doesnt fill input fields. than it will print error. but i want to keep the values safe. that way user dont have to keep fill
in data again and again

This function doesn't work anymore: $_SERVER['REQUEST_METHOD']

Read this:

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

Read my post in your other thread about your variable!

http://www.daniweb.com/web-development/php/threads/440629/how-to-save-login-information

by the sound of it, you need something like

<input type="text" name="username" id="login_username" class="login_field" value="<?php if(isset($val = $_POST['username'] ) )
            {echo $val; }
   ?>" />

This is gonna save your users from typing whatever they've typed before if something goes wrong.

 <input type="text" name="username" id="login_username" class="field" value="<?php if(isset($val == $_POST['username'])){echo $val;}?>" />

Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')'

<input type="text" name="username" id="login_username" class="login_field" value="<?php if(isset($val = $_POST['username'])){echo $val; }?>"/>

Parse error: syntax error, unexpected '=', expecting ',' or ')' in C:\xampp\htdocs\E_COMMERCE\login.php on line 122
not sure what this error means.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.