SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    logging problems...

    i ahve a problem with logging in..i get no errors..but when i type in a correct username and password i keep getting 'wrong password' message when i know this is wrong...i think im not connecting to my database correctly can someone help..i will post my login and database script.the validation works, it just wont let me log on pleae can someone help

    loginscript

    <?php
    if(isset($_POST['submit'])){
    require_once('c:\webserver\Apache2\htdocs\prac\mysql_connect.php');
    function escape_data($data){
    global $dbc;
    if (ini_get('magic_quotes_gpc')){
    $data=stripslashes($data);
    }
    return mysql_real_escape_string (trim ($data), $dbc);
    }
    $message = NULL;
    if(empty($_POST['username'])){
    $u = FALSE;
    $message .= '<p>You forgot to enter your username</p>';
    }else{
    $u = escape_data($_POST['username']);
    }
    if(empty($_POST['password'])){
    $p = FALSE;
    $message .= '<p>You forgot to enter your password</p>';
    }else{
    $p = escape_data($_POST['password']);
    }

    if ($u && $p){

    $query= "SELECT id, fname FROM staff WHERE username='$u' AND password=PASSWORD('$p')";
    $result = @mysql_query ($query);
    $row = mysql_fetch_array ($result, MYSQL_NUM);
    if ($row){
    session_start();
    $_SESSION['fname']= $row[1];
    $_SESSION['id']= $row[0];
    header ("Location: http://" .$_SERVER['HTTP_HOST'] . dirname($_Server['PHP_SELF']) . "loggedin.php?" .SID);
    exit();
    }else{
    $message = '<p>Your password does not match</p>';

    }



    mysql_close();

    }else{
    $message .= '<p><font color="red" size ="+1">Please try again</font></p>';

    }

    }
    if(isset($message)){
    echo '<font color="red">', $message, '</font>';
    }
    ?>

    <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <fieldset>
    <p>Username:
    <input type="text" name="username" size="20" maxlength="20" value="<?php if(isset($_POST['username'])) echo $_POST['username'];?>" />
    <br>
    Password:
    <input type="password" name="password" size="20" maxlength="20" />
    </p>
    </ br>
    <input type="submit" name="submit" value="Login" align=center />
    </div>
    </form>


    here is my database script mysql_connect.php

    <?php

    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_HOST', 'localhost');
    define('DB_Name', 'hotel');
    $dbc = @mysql_connect ('localhost', 'root', '');
    mysql_select_db ('hotel');
    ?>

  2. #2
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe because your escaping your password?

    I dunno

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no its not that
    anyone else


Bookmarks

Posting Permissions

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