Results 1 to 2 of 2

Thread: help completing this code

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    help completing this code

    this is my checkuser.php page! I have a login.php page which has a textbox with username and password fields on it. Is this correct?

    PHP Code:
    <?PHP 
    mysql_connect 
    (localhostusername,  password); 
    mysql_select_db (Table); 

    $result mysql_query ("select username, password, access_level from Members where username = $username");

    if((
    $username==$mysql_username) && $password ==$mysql_password) {  
    setcookie("access_level",$mysql_access_level,time() + 3600);  
    header("Location: page.php"); }  
    else { 
    header("Location: login.php"); }
    let me know if it has any problems
    Last edited by kiwis; Jun 14th, 2004 at 12:43 AM.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: help completing this code

    Originally posted by kiwis
    this is my checkuser.php page! I have a login.php page which has a textbox with username and password fields on it. Is this correct?

    PHP Code:
    <?PHP 
    mysql_connect 
    (localhostusername,  password); 
    mysql_select_db (Table); 

    $result mysql_query ("select username, password, access_level from Members where username = $username");

    if((
    $username==$mysql_username) && $password ==$mysql_password) {  
    setcookie("access_level",$mysql_access_level,time() + 3600);  
    header("Location: page.php"); }  
    else { 
    header("Location: login.php"); }
    let me know if it has any problems
    Quite a few.

    1) You're not using superglobals.
    2) You're not surrounding text with quotes in the query.
    3) Where does $_mysql_username come from?
    4) You need to do a mysql_fetch_array() to get the record.

    PHP Code:
    mysql_connect (localhostusername,  password); 
    mysql_select_db (Table); 

    $users mysql_query ("select username, password, access_level from Members where username = '" $_POST['username'] ."' AND password = '" $_POST['password'] . "'");

    if (
    $user mysql_fetch_array($users)) { 
        
    setcookie("access_level",$mysql_access_level,time() + 3600);  
        
    header("Location: page.php"); 
    }  else { 
        
    header("Location: login.php"); 

    Also note that I put password checking in the query as well. This will remove the need for an extra if-statement later.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width