www.webdeveloper.com
Results 1 to 4 of 4

Thread: Login Script Problem

  1. #1
    Join Date
    Oct 2005
    Posts
    593

    Login Script Problem

    Hi there,
    Little problem my script. It worked fine earlier when was only one user in my database but now ive added more it dosent work!

    example username = srobinson
    password = password

    www.loddonexplorers.co.uk/Design/New/Login.php

    Code is below,
    Cheers

    PHP Code:
    <?php session_start(); ?>
    <?php 
    require("Template_Top.php"); ?>

    <h2> Register System </h2>

    <?php

    include("ErrorMailer.php");

    $_SESSION['Username'] = "";
    IF (
    $_POST['_submit_check']) :
      IF (
    validate_form()) :
        
    $_SESSION['Username'] = $_POST['Username'];
        
    process_form();
      ELSE :
        
    show_form('Enter a valid username and password!');
      ENDIF;  
    ELSE :
      
    show_form();
    ENDIF; 

    function 
    process_form() {

    $DBUserID$_SESSION[Username];
    $DBDate date('Y-m-d');

    $userconn   = @mysql_connect("localhost""lx""xin") or die("ERROR: Unable to establish database connection");
    $dbconn     = @mysql_select_db("loddouk1_main") or die( "Unable to select database");

    $sql "SELECT * FROM tblRegister WHERE UserID='$DBUserID' AND `TimeStamp`='$DBDate' ORDER BY `TimeStamp` DESC LIMIT 1";
    $qry mysql_query($sql) or dying_mail("Query failed ($sql) " mysql_error() . "<br><br>This error has been reported! I'll fix it sometime soon (Very soon...) !");

    IF (
    $qry) :
      IF (
    mysql_num_rows($qry) == 1) :
        print 
    "You have already logged in today! Thank you.";
      ELSE :
        
    $sql2="INSERT INTO tblRegister VALUES(null,'$DBUserID','$DBDate')" ;
        
    $Qry2 mysql_query($sql2) or dying_mail("Query failed ($sql2) " mysql_error()); ;
        IF (
    $Qry2) :
          print 
    'You are logged in as: <b>'.$_SESSION['Username'].'</b>'.str_repeat('&nbsp;'10).'<a href="RegLogout.php">Logout</a><br />';
          print 
    '<p>You can continue processing as a logged-in user ............</p>';
        ELSE :
          print 
    "test";
        ENDIF;
      ENDIF;

    /*

      $sql4 = "SELECT Admin FROM tblExplorerGroup WHERE Username='$DBUserID' LIMIT 1";
      $qry4 = mysql_query($sql4)  or dying_mail("Query failed ($sql4) " . mysql_error()); ;
      IF ($qry4) :
        $ADMINrole = mysql_fetch_assoc($qry4);
        IF($ADMINrole['Admin'] == "Y") :
          echo "You Can Administer this page!";
          exit;
        ELSE :
          echo "You Cannot Administer this page!";
        ENDIF;
      ENDIF; 

    */

    ENDIF;
    }


    function 
    show_form($errors '') {
      IF (!
    is_array($errors)) :
        
    $errors = array($errors);
      ENDIF;
      IF (
    count($errors) > 0) :
        print 
    '<span style="color:red">';
        FOREACH (
    $errors as $thisERROR) :
          print 
    '<ul><li><b>' $thisERROR '</b></li></ul>';
        ENDFOREACH;
        print 
    '</span>';
      ENDIF;  
      print 
    '<form name="authForm" method="POST" action="'.$_SERVER['PHP_SELF'].'">';
      print 
    '<table><tr><td width="50">';
      print 
    'Username </td><td width="50"><input type="text"     name="Username" value="' htmlentities($_POST['Username']) . '"> <br />';
      print 
    '</td></tr><tr><td width="50">Password</td><td width="50"><input type="password" name="Password" value="' htmlentities($_POST['Password']) . '"> <br />';
      print 
    '</td></tr><tr><td width="50"></td><td width="50"><input type="submit" name="login" value="Login" /></td></tr></table>';
      print 
    '<input type="hidden" name="_submit_check" value="1"/>';
      print 
    '</form>';
    }

    function 
    validate_form() {
      
    $userconn   = @mysql_connect("x""xn""x") or die("ERROR: Unable to establish database connection");
      
    $dbconn     = @mysql_select_db("loddouk1_main") or dying_mail"Unable to select database");

      
    $UserID     $_POST['Username'];
      
    $UserPass   $_POST['Password'];

      
    $sql3 "SELECT Username FROM tblExplorerGroup WHERE Username='$UserID' AND Password='$UserPass' LIMIT 1";
      
    $qry3 = @mysql_query($sql3) or die("Query failed ($sql3) " mysql_error()); ;

      
    $returnCODE FALSE;
      IF (
    $qry3) :
        IF (
    mysql_num_rows($qry3) == 1) :
          
    $returnCODE TRUE;
        ENDIF;
      ENDIF;
      return 
    $returnCODE;
    }

    ?> 
    <?php require("Template_Bottom.php"); ?>
    Last edited by scottyrob; 01-09-2007 at 03:49 PM.

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Hi,
    Are you'sure the password isn't encrypted in the table?

  3. #3
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    If you changed this:
    PHP Code:
    $returnCODE FALSE;
    IF (
    $qry3) :
      IF (
    mysql_num_rows($qry3) == 1) :
        
    $returnCODE TRUE;
      ENDIF;
    ENDIF;
    return 
    $returnCODE
    t:
    PHP Code:
    $returnCODE FALSE;
    IF (
    $qry3) :
      
    $ROWSfound mysql_num_rows($qry3);
      IF (
    mysql_num_rows($qry3) == 1) :
        
    $returnCODE TRUE;
      ELSE :
        print 
    $ROWSfound "<hr>" $sql3 "<br>";
      ENDIF;
    ENDIF;
    return 
    $returnCODE
    it could tell us part of what may have happened.

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    I copied the relevant part of the script (validate_form) to my server, and set up a table with 3 users:

    sparson - password
    night - shift
    loddon - explorers.

    It's validating here... See: http://www.nightshift58.com/webdev/test.password.php

    So the problem may well be somewhere else...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles