checking fields of log in form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpbeginner
    New Member
    • Jul 2007
    • 4

    checking fields of log in form

    My question is simple.

    When a user types in a blank username or password, I want to say sorry, you must enter a username and a password in a different colour.

    Can someone suggest how to do this. I thought I woiuld be able to find something quick online, but either everything seems too complicated or I just cannot find what I want.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    That's simple enough for me to give a straight answer to.

    [code=php]<?php
    if(!empty($_POS T)) // Form has been submitted
    {
    if(!isset($_POS T['username'], $_POST['password']))
    {
    $error = "You must fill in all fields.";
    }
    else
    {
    // Submit and process the data
    }
    }
    ?>

    <form method="post" action="" >
    <input type="text" name="username" value="<?php
    echo isset($_POST['username']) ? $_POST['username'] : '';?> />
    <input type="password" name="password" value="<?php
    echo isset($_POST['password']) ? $_POST['password'] : '';?> />
    <input type="submit" value="Submit" />
    </form>[/code]

    That should do it. Inform me if there are any typos.


    You just have to check each form field (which you should ALWAYS do anyway).

    Comment

    Working...