SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Nottingham, UK
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Login Script Problem.

    keep getting this error message from my login script


    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/manpreetsandhu.com/public_html/login3.php on line 54
    PHP Code:
    <?php
        
        
        
        session_start
    ();
        
        
        
        require_once(
    'common_db.php');
        
        
        
        
    //function error_message($msg){
        //echo "<script>alert(\"$msg\");history.go(-1)</script>";
        //exit;
        //}
        
        //if(empty($username)) error_message("Enter Your Login Details");
        
        
        
    if ((!isset($_POST['username'])) && (!isset($_POST['password'])))
        {
            echo             
    "<center><table>
                            <tr>
                                <b>&raquo;Funky Monkey Login</b>
                            </tr>
                            <tr><form name=\"auth\" method=\"post\" action=\"login3.php\">
                                <td>Username: </td>
                                  <td><input class=\"textfield\" type=\"text\" name=\"username\" size=\"10\"></td>
                             </tr>
                            <tr>    
                                <td>Password: </td>
                                 <td><input class=\"textfield\" type=\"password\" name=\"password\" size=\"10\"></td>
                            </tr>
                            <tr>    
                                <td><input type=\"hidden\" name=\"action\" value=\"login\"><input class=\"button\" type=\"submit\" name=\"Submit\" value=\"Login\">
                                 <input type=\"reset\" name=\"reset\" value=\"Reset\"></td>
                            </tr>
                            <tr>
                                <td><a href=\"
    $register_script\"> Register</a> - if you don't have an account</td>
                            </tr>
                            </form>
                            </table></center>"
    ;
            }
        
        
        
        if ((isset(
    $_POST['username'])) && (isset($_POST['password'])))
        {
            
            
    $link_id db_connect();
            
            
    $query "SELECT * FROM customers WHERE username='".$_POST['username']."' AND password='".$_POST['password']."'"
            
    $getUserInfo mysql_fetch_array($query,$link_id);
            
    $result mysql_query($query,$link_id);
            if (
    mysql_num_rows($result) != )
                
    //$num_rows = mysql_num_rows($result);
                
                //if($result != true)
            
    {
                
    //var_export($result);
                //echo $_POST['username'];
                //var_export($query);
                //var_export($link_id);
                
    error_message("Invalid Username/Password");
            }
            else            
                
    //if(($_POST['password']) != ($getUserInfo['password']));
                //{
                //error_message("Password Invalid");
                //}
                //if (mysql_num_rows($result) > 0)
                    
                    
                    
                    
                    
    if ($getUserInfo['validated'] == '0'){
                        
    error_message("You must Validate your account");
                        
                        
                    }else
            
            if(
    $_POST['password'] == $getUserInfo['password']) 
            {
                
    $_SESSION['customer_id'] = $getUserInfo['customer_id'];
                
    session_register("customer_id");
                
    session_register("username");
                
                
                
    $_SESSION['valid_user'] = $getUserInfo['customer_id'];
                
    $_SESSION['username'] = $getUserInfo['username'];
                
    $_SESSION['rank'] = $getUserInfo['rank'];
                
    $_SESSION['first_name'] = $getUserInfo['first_name'];
                
    $_SESSION['validated'] = $getUserInfo['validated'];
                
    $_SESSION['surname'] = $getUserInfo['surname'];
                
                
                if (
    $_SESSION['validated'] == '0'){
                    
    session_unregister('customer_id');
                    
    error_message("You must Validate your account");
                    
                    
                }
                
                if     (
    $_SESSION['rank'] == '2'){
                    
    header'refresh: 0; url=index.php' );
                    exit;
                }
                
                else
                {
                    if(
    $_SESSION['rank'] != '2'){
                        
    header'refresh: 0; url=index.php' );
                        exit;
                    }
                }
                
                
                
                
            }
        }
        
        
        
        
    ?>

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should really mark line 54, saves us having to guess.

    Having said that, I guess )) the lines causing problems are

    PHP Code:
     $getUserInfo mysql_fetch_array($query,$link_id);
     
    $result mysql_query($query,$link_id); 
    they should be

    PHP Code:
     $result mysql_query($query,$link_id);
     
    $getUserInfo mysql_fetch_assoc($result,$link_id); 
    You need to execute the query (mysql_query) before you can fetch the results (mysql_fetch_assoc).


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
  •