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 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Help with Mysql Query

    Hi,

    I am using the script below and i keep getting : No such username . . . and the info the database is there, what could be stopping me? The connect file also works fine.

    Thanks

    Steven

    PHP Code:
    <?php

    /* ADMIN LOGIN */

    echo "<title>Admin Login</title>";
    include(
    'connect.php');
    if (
    $_POST['submit']) {
    $user $_POST['username'];
    $password $_POST['password'];
    $mdpass md5($password);
    $sql1 mysql_query("SELECT * FROM admins WHERE username = $user");
    $r1 = @mysql_num_rows($sql1);
    if (
    $r1 != 1) {
    echo 
    "No such username . . .";
    die();
    } else {
    $sql2 mysql_query("SELECT * FROM admins WHERE password = $mdpass AND username = $user");
    $r2 = @mysql_num_rows($sql2);
    if (
    $r2 != 1) {
    echo 
    "Incorrect Password";
    die();
    } else {
    echo 
    "Logged In, Thankyou.";
    $_SESSION['logged'] = 1;
    echo 
    "<a href=\"index.php\">Home</a>";
    }
    }
    } else {
    // Form not submit
    }

    ?>
    <head>

    <style type="text/css">
    .text {
    font-size:12px;
    font-family:Verdana, Arial, Helvetica, sans-serif;
    }
    </style>
    </head><div class="text">
    <p>Please use the form below to login to the Admin Control Panel.</p><br />
    <form name="login" action="login.php" method="post">
    Username: <input type="text" name="username" /><br />
    Password: <input type="password" name="pass" /><br /><br />
    <input type="submit" name="submit" value="Login"><input type="reset" name="reset" />
    </form></div>
    Last edited by Webmonkey; 08-30-2006 at 09:58 AM.

  • #2
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I've Fixed it using this code:, Its becuase i change if ($res!=1) to is_object($res).

    PHP Code:
    <?php

    /* ADMIN LOGIN */

    echo "<title>Admin Login</title>";
    include(
    'connect.php');
    if (
    $_POST['submit']) {
    $user $_POST['username'];
    $password $_POST['password'];
    $mdpass md5($password);
    $sql1 mysql_query("SELECT * FROM admins WHERE username = $user");
    $res = @mysql_num_rows($sql1);
    if (
    is_object($res)) {
    echo 
    "$res";
    echo 
    "No such username . . .";
    die();
    } else {
    $sql2 mysql_query("SELECT * FROM admins WHERE password = $mdpass AND username = $user");
    $r2 = @mysql_num_rows($sql2);
    if (
    is_object($r2)) {
    echo 
    "Incorrect Password";
    die();
    } else {
    echo 
    "Logged In, Thankyou.";
    $_SESSION['logged'] = 1;
    echo 
    "<a href=\"index.php\">Home</a>";
    }
    }
    } else {
    // Form not submit
    }

    ?>
    <head>

    <style type="text/css">
    .text {
    font-size:12px;
    font-family:Verdana, Arial, Helvetica, sans-serif;
    }
    </style>
    </head><div class="text">
    <p>Please use the form below to login to the Admin Control Panel.</p><br />
    <form name="login" action="login.php" method="post">
    Username: <input type="text" name="username" /><br />
    Password: <input type="password" name="pass" /><br /><br />
    <input type="submit" name="submit" value="Login"><input type="reset" name="reset" />
    </form></div>

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can also just test for true/false as in "if (!$res) {}" (not the C way).


  •  

    Posting Permissions

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