SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Login System & View User is not working!

    Login system is not working... Sentry.php - > all functions work except last function.

    You can see in UserFunc how I cheated the system so i could test the parts that needed me to be logged in but I really need to get this fixed to continue...
    --------------------------------------
    The error message:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in "aoc_cms\includes\DbConnector.php" on line 50...

    I get this error from "aoc_cms/cmsadmin/viewUser.php?name=hello1" and I think it happens when attempting to fetch the array (function fetchArray()) for $row...
    --------------------------------------
    well those are the two problems I worked on all night and couldn't solve... and it's not that I don't have the user "hello1" in my database.

    I have attached my site so maybe someone who has the time can help me.

    Many thanks to all.
    Last edited by Leoj00; Jul 26, 2007 at 17:33.

  2. #2
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The query is probably invalid, and so it does not return a valid MySQL resource.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation

    line 50 of DbConnector.php:

    Code:
    48  //*** Function: fetchArray, Purpose: Get array of query results ***
    49  function fetchArray($result) {
    50 	 return mysql_fetch_array($result);
    51  }
    viewUser.php:

    Code:
    <?php
    // Require the database class
    require_once('.../includes/DbConnector.php');
    
    // Create a new DbConnector object
    $connector = new DbConnector();
    
    // Execute the query to retrieve the selected article
    $result = $connector->query('SELECT username,lastonline,created,triggeredby,triggertitle FROM cmsonline WHERE username = '.$HTTP_GET_VARS['name']);
    
    // Get an array containing the resulting record
    $row = $connector->fetchArray($result);
    
    echo $row['username'];
    echo $row['triggeredby'];
    ?>

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up asdas

    Finally found the syntax error... fixed with this:

    // Execute the query to retrieve the selected article
    $theName = $HTTP_GET_VARS[name];
    $result = $connector->query("SELECT username,lastonline,created,triggeredby,triggertitle FROM cmsonline WHERE username = '$theName'");

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation

    can anyone help with my other problem?

    Login system is not working... Sentry.php - > all functions work except last function.
    Sentry.php:
    Code:
    <?php
    ////////////////////////////////////////////////////////////////////////////////////////
    // Class: sentry
    // Purpose: Control access to pages
    ///////////////////////////////////////////////////////////////////////////////////////
    class sentry {
    	
    	var $loggedin = false;		//  Boolean to store whether the user is logged in
    	var $userdata;			//  Array to contain user's data
    	
    	function sentry(){
    		session_start();
    		header("Cache-control: private"); 
    	}
    	
    	//======================================================================================
    	// Log out, destroy session
    	function logout(){
    		unset($this->userdata);
    		session_destroy();
    		return true;
    	}
    
    	//======================================================================================
    	// Log in, and either redirect to goodRedirect or badRedirect depending on success
    	function checkLogin($user = '',$pass = '',$group = 10,$goodRedirect = '',$badRedirect = ''){
    
    		// Include database and validation classes, and create objects
    		require_once('DbConnector.php');
    		require_once('Validator.php');
    		$validate = new Validator();
    		$loginConnector = new DbConnector();
    		
    		// If user is already logged in then check credentials
    		if ($_SESSION['user'] && $_SESSION['pass']){
    
    			// Validate session data
    			if (!$validate->validateTextOnly($_SESSION['user'])){return false;}
    			if (!$validate->validateTextOnly($_SESSION['pass'])){return false;}
    
    			$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."' AND thegroup <= ".$group.' AND enabled = 1');
    
    			if ($loginConnector->getNumRows($getUser) > 0){
    				// Existing user ok, continue
    				if ($goodRedirect != '') { 
    					header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
    				}			
    				return true;
    			}else{
    				// Existing user not ok, logout
    				$this->logout();
    				return false;
    			}
    			
    		// User isn't logged in, check credentials -Not Working
    		}else{	
    			// Validate input
    			if (!$validate->validateTextOnly($user)){return false;}
    			if (!$validate->validateTextOnly($pass)){return false;}
    
    			// Look up user in DB
    			$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '$user' AND pass = PASSWORD('$pass') AND thegroup <= $group AND enabled = 1");
    			$this->userdata = $loginConnector->fetchArray($getUser);
    
    			if ($loginConnector->getNumRows($getUser) > 0){
    				// Login OK, store session details
    				// Log in
    				$_SESSION["user"] = $user;
    				$_SESSION["pass"] = $this->userdata['pass'];
    				$_SESSION["thegroup"] = $this->userdata['thegroup'];
    								
    				if ($goodRedirect) { 
    					header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
    				}
    				return true;
    
    			}else{
    				// Login BAD
    				unset($this->userdata);
    				if ($badRedirect) { 
    					header("Location: ".$badRedirect) ;
    				}		
    				return false;
    			}
    		}			
    	}
    }	
    ?>
    Login.php:
    Code:
    <?php
    // Require the userFunc class
    require_once('.../includes/UserFunc.php');
    
    // Update user's timestamp
    $address = $_SERVER['REQUEST_URI'];
    $title = "Log In";
    $userFunc = new userFunc();
    $userFunc->updateStamp($address,$title);
    
    require_once("../includes/Sentry.php");
    
    $sentry = new Sentry();
    if ($HTTP_POST_VARS['user'] != ''){
    	$sentry->checkLogin($HTTP_POST_VARS['user'],$HTTP_POST_VARS['pass'],4,'welcome.php','failed.php');
    }
    
    if ($HTTP_GET_VARS['action'] == 'logout'){
    	if ($sentry->logout()){
    		echo '<center>You have been logged out</center><br>';
    	}
    }
    ?>
    <html>
    <head>
    <title><?php echo($title); ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <table width="25&#37;" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000066">
      <tr>
        <td align="center" bgcolor="#000066"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Login</strong></font></td>
      </tr>
      <tr>
        <td bordercolor="#FFFFFF"><form name="form1" method="post" action="login.php">
            <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
    &nbsp;User:
              <input type="text" name="user">
            </font></p>
            <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;Pass:
                  <input type="password" name="pass">
            </font></p>
            <p align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
              <input type="submit" name="Submit2" value="Submit">
            </font></p>
          </form>
            <div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="login.php?action=logout">Logout</a>&nbsp;</font></div>
        </td>
      </tr>
    </table>
    </body>
    </html>

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump for help!

    please attempt to help b/c I am stuck =X

  7. #7
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay bumping this one last time


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
  •