Intranet Journal

Go Back   IT Management Forum > Intranet Journal

Intranet Journal The new discussion forum for Intranet Journal readers. Leave comments and questions for IJ authors. Suggest story ideas and provide feedback.

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-21-2009, 07:45 PM
FaT3oYCG FaT3oYCG is offline
Registered User
 
Join Date: Jan 2009
Posts: 11
Problem with Sentry.php (query variable is empty)

this is the most strange problem i have come accross, i cant see any problems with my code and i have tried everything i can think of to try and fix it but yet the problem still persists

here is my sentry.php file
Code:
<?php
	class Sentry
	{
		var $loggedin = false;
		var $userdata;

		function sentry()
		{
			session_start();
			header("Cache-control: private"); 
		}
		
		function logout()
		{
			unset($this->userdata);
			session_destroy();
			return true;
		}

		function checkLogin($user = '',$pass = '',$group = 10,$goodRedirect = '',$badRedirect = '')
		{
			require_once('DBConnector.php');
			require_once('Validator.php');
			$validate = new Validator();
			$connector = new DBConnector();

			if($_SESSION['user'] && $_SESSION['pass'])
			{
				if(!$validate->validateTextOnly($_SESSION['user']))
				{
					return false;
				}
				if(!$validate->validateTextOnly($_SESSION['pass']))
				{
					return false;
				}

				$getUser = $connector->Query("SELECT * FROM members WHERE Username='" . $_SESSION['user'] . "' AND Password='" . $_SESSION['pass'] . "' AND Group<='" . $group . "' AND Status=1");

				if($connector->GetNumRows($getUser) > 0)
				{
					if($goodRedirect != '')
					{
						header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
					}
					return true;
				}else{
					$this->logout();
					return false;
				}
			}else{
				if(!$validate->validateTextOnly($user))
				{
					return false;
				}
				if(!$validate->validateTextOnly($pass))
				{
					return false;
				}

				$getUser = $connector->Query('SELECT * FROM members WHERE Username="$user" AND Password=MD5("$pass") AND Group<="$group" AND Status="1"');
				$this->userdata = $connector->GetArray($getUser);

				if($connector->GetNumRows($getUser) > 0)
				{
					$_SESSION["user"] = $user;
					$_SESSION["pass"] = $this->userdata['Password'];
					$_SESSION["group"] = $this->userdata['Group'];

					if ($goodRedirect)
					{
						header("Location: ".$goodRedirect."?".strip_tags(session_id()));
					}
					return true;
				}else{
					unset($this->userdata);
					if ($badRedirect)
					{
						header("Location: ".$badRedirect);
					}
					return false;
				}
			}
		}
	}
?>

the problem is with the query line that is supposed to return the resource id
Code:
$getUser = $connector->Query('SELECT * FROM members WHERE Username="$user" AND Password=MD5("$pass") AND Group<="$group" AND Status="1"');
it doesnt store or return any value, e.g. if i echo it normally it would say something like Resource #id3, but nothing if i echo it it returns nothing at all, my query is correct i am sure as i have tested it in phpmyadmin by means of sql querying and it returs values then.

here are some additional errors that dont make sense other than the fact it is because the query returns nothing that are displayed at the top of the login.php page when you try to login
Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\xampp\htdocs\phpcms\includes\DBConnector.php on line 41

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in H:\xampp\htdocs\phpcms\includes\DBConnector.php on line 36

Warning: Cannot modify header information - headers already sent by (output started at H:\xampp\htdocs\phpcms\includes\DBConnector.php:41) in H:\xampp\htdocs\phpcms\includes\Sentry.php on line 79
hope someone can spot anything i have missed coz im stumped on this one

cheers

craig
Reply With Quote
  #2 (permalink)  
Old 03-22-2009, 07:35 AM
FaT3oYCG FaT3oYCG is offline
Registered User
 
Join Date: Jan 2009
Posts: 11
nevermind got some help from the php freaks website, it was because one of the feilds in my database was named group which is a reserved word all i needed to do was change it to UGroup and then it all worked perfectly
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 02:24 AM.





Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0