Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Login Script Help

    I'm going to refer to my thread yesterday about developing a registration system for users logging in.

    This morning I've been working on a login script.

    My login form is as follows:

    PHP Code:
    <form name="form1" method="post" action="checklogin.php">
    <
    p>Please Enter Your
    <label>Username: <input name="myusername" type="text" id="myusername" /></label> <label>Email: <input name="myemail" type="text" id="myemail" /></label> <label>Password: <input name="mypassword" type="password" id="mypassword" /></label><input type="submit" name="Submit" value="login" /></form
    My checklogin.php code is:
    PHP Code:
    <?php

    include 'db.inc.php';
    $tbl_name="members"// Table name

    // username and password sent from signup form
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];
    $myemail=$_POST['myemail'];

    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and email='$myemail'";
    $result=mysql_query($sql);

    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword and $myemail, table row must be 1 row

    if($count==1){
    // Register $myusername, $mypassword, $myemail and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword");
    session_register("myemail");
    header("Location:login_success.php");
    }
    else {
    echo 
    "Wrong Username or Password";
    }
    ?>
    and finally, my login_success.php is

    PHP Code:
    // Check if session is not registered , redirect back to main page.
    // Put this code in first line of web page.
    <?
    session_start
    ();
    if(!
    session_is_registered(myusername)){
    header("location:main_login.php");
    }
    ?>

    <html>
    <body>
    Login Successful
    </body>
    </html>
    When I click on 'login' I'm getting the error that is being echoed in my checklogin.php code:

    "Wrong username and password"

  • #2
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    The error message shows if there's no record or more than one record by the credentials that you use. Also try testing with basic chars only: username, password and email with only @ [a-z][A-Z][0-9].
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •