0

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;
            }
            ?>
3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by hwoarang69
2

@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

0

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.

0
 <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.

Edited by hwoarang69

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.