0

just as i know that is the login form and the register form is need to have the error handling and i'm using a php for the main code language, there is such an errors handling if i put into an php language its kind of silly, i mean the design is more or less than nothing

i want to put an error handling like "Your Username and Password Combination is Incorrect", 'We Can\'t Find That Username', 'You Need To Enter a Username And a Password',

on the footer page it will pop up message if the user is do something wrong with the form

this is my code html:

<div id="header">
    <div id="header-content">
        <div id="logo"> <a href="index.php" style="text-decoration:none;">
                    logo</a>

        </div>
        <div id="searchbox">
            <input type="text" placeholder="Search" size="50" class="searchbox">
        </div>

PHP

if(empty($_POST) === false){
$username = $_POST['input-username'];
$password = $_POST['input-password'];

    if(empty($username) === true || empty($password) ===true){
        $errors[] = 'You Need To Enter a Username And a Password';
        }
        else if(user_exists($username) === false){
        $errors[] = 'We Can\'t Find That Username';
            }

        else{
            $login = login($username, $password);

                if($login === false){
                    $errors[] = 'Your Username and Password Combination is Incorrect';
                    }
                else{
                    $_SESSION['user_id'] = $login;
                    header('Location: home.php');

                    }
            }

        print_r($errors);
}

and back to form in html

<div id="users">
    <form method="post" action="" name="signin-form">
        <table border="1">
            <tr>
                <td>Username</td>
                <td>
                    <input type="text" name="input-username" id="input-username">
                </td>
                <td>Password</td>
                <td>
                    <input type="password" name="input-password" id="input-password">
                </td>
                <td>
                    <input type="submit" name="sign-in" id="sign-in" value="Log in">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="checkbox" name="remember-me">
                    <label id="information">Keep Me Eating Picture</label>
                </td>
                <td colspan="2"> <a href="#" id="forgotpass">Forgotten My Username or Password</a>

                </td>
            </tr>
        </table>
    </form>
    <button id="sign-up">Sign Up</button>
</div>
</div>
</div>

there is some core items that i can't show in here such as connect to database and function page(which is the page full of function that i need)

im showing this code for information that i'm using array errors handling but i want to show the error message on footer side somebody please help me btw sorry for my english, and thx for your concern

4

1 回答 1

0

If I understand correctly, you want to show the error on the footer page.

You could try something like: (which I tested with 2 small files)

NOTE: I could not test with brackets, but this worked.

$errors = include 'footer_error_message.php';

yet do try with brackets, it should work.

$errors[] = include 'footer_error_message.php';

Then in your footer.php file for example you would have something to the affect of:

echo "Your Username and Password Combination is Incorrect";

EDIT (added popup JS message)

In your error message file, you can do the following:

You can use this as your popup error message. (in error_incorrect_info.php for example)

<?php

$errormessage = "Your Username and Password Combination is Incorrect";

echo "<script language=\"javascript\" type=\"text/javascript\">
    alert('$errormessage');

</script>
";

?>

Reformatted could look like this:

if(empty($_POST) === false){
$username = $_POST['input-username'];
$password = $_POST['input-password'];

    if(empty($username) === true || empty($password) ===true){
        $errors[] = include 'error_enter_info.php';
        }
        else if(user_exists($username) === false){
        $errors[] = 'We Can\'t Find That Username';
            }

        else{
            $login = login($username, $password);

                if($login === false){
                    $errors[] = include 'error_incorrect_info.php';
                    }
                else{
                    $_SESSION['user_id'] = $login;
                    header('Location: home.php');

                    }
            }

        print_r($errors);
}
于 2013-09-01T14:00:59.303 回答