Web Analytics Made Easy -
StatCounter login system - CodingForum

Announcement

Collapse
No announcement yet.

login system

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • login system

    I am trying to create a login system. The values in the password and username textboxes are checked against my database and if they are in there access is granted. However, when the page loads the condition is automatically checked with blank values and so access is denied. Is there a way of preventing the page from automatically using these blank values upon loading??

    thanks

    My code is below

    <?php
    $username = $_REQUEST['username'];
    $password = $_REQUEST['password'];

    mysql_connect("localhost", "root", "dinosaur") or die(mysql_error());

    mysql_select_db("info") or die(mysql_error());



    $result = mysql_query("SELECT * FROM users WHERE username = '$username' && password='$password'");

    $row = mysql_fetch_array($result);//the result

    if(($row['username'] == $username) && ($row['password'] == $password) && (mysql_numrows($result) == 1))//check username and password

    {




    ?><div border = 1 color="red" align=middle>

    You have have successfully logged in. You will be redirected shortly ...
    </div>
    <meta http-equiv="refresh" content="2; URL=home.php">
    <?php


    }
    elseif (mysql_numrows($result) == 0) {

    echo "incorrect login"; //shows when page loads because no results returned for the blank text boxes
    }


    ?>

  • #2
    PHP Code:
    <?php
    if (!empty($_POST['password']) && !empty($_POST['username'])){
    $username $_POST['username'];
    $password $_POST['password'];

    mysql_connect("localhost""root""dinosaur") or die(mysql_error());

    mysql_select_db("info") or die(mysql_error());



    $result mysql_query("SELECT * FROM users WHERE username = '$username' && password='$password'");

    $row mysql_fetch_array($result);//the result

    if(($row['username'] == $username) && ($row['password'] == $password) && (mysql_numrows($result) == 1))//check username and password

    {




    ?><div border = 1 color="red" align=middle>

    You have have successfully logged in. You will be redirected shortly ...
    </div>
    <meta http-equiv="refresh" content="2; URL=home.php">
    <?php


    }
    elseif (
    mysql_numrows($result) == 0) {

    echo 
    "incorrect login"//shows when page loads because no results returned for the blank text boxes
    }
    }
    ?>

    Comment

    Working...
    X