Click here to Skip to main content
15,504,490 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: trying to write a cookie Pin
MacRaider422-Mar-11 6:26
MacRaider422-Mar-11 6:26 
AnswerRe: trying to write a cookie Pin
Tony Wright (UK)24-Feb-11 3:39
Tony Wright (UK)24-Feb-11 3:39 
Questionwhy i cound't access apple's server with php curl Pin
wjun1976121918-Feb-11 6:10
wjun1976121918-Feb-11 6:10 
AnswerRe: why i cound't access apple's server with php curl Pin
Tom Chantler23-Feb-11 22:21
professionalTom Chantler23-Feb-11 22:21 
QuestionData normalization Pin
Mutugi from Nairobi14-Feb-11 21:14
Mutugi from Nairobi14-Feb-11 21:14 
AnswerRe: Data normalization Pin
Eddy Vluggen19-Feb-11 4:04
professionalEddy Vluggen19-Feb-11 4:04 
QuestionGetting google photo result by php Pin
ty-exexch-ko10-Feb-11 10:31
ty-exexch-ko10-Feb-11 10:31 
Questionmysql_query error Pin
komanche7-Feb-11 23:31
komanche7-Feb-11 23:31 
Hello all.
Am having a major problem with my code.I cant find an error in the code but i keep getting this messages
"Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 223

Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203

Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 251

Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 194

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 195

Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 261

Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203"

and the php code is
<?php
	/** this is the database connections specification files
		can only be changed by an administrator 
	*/
	//connect to database

	require_once("constants.php");
	
	class MySQLDB
	{
		var $connection;				//the mysql database connection
		var $num_active_user;			//number of active users viewing site
		var $num_active_guests;			//number of guests viewing site
		var $num_members;				//number of signed users
		
		//class constructor
		function MySLQDB()
		{
			
			
			$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die (mysql_error());
			mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
			
			//only query database to find out number of members when getnummembers() is called for the first time, until then
			//default value is set
			$this->num_members = -1;
			
			if(TRACK_VISITORS)
			{
				//calculate number of users at site
				$this->calcNumActiveUsers();
				
				//calculate number of guests at site
				$this->calcNumActiveGuests();
			}
		}
		//confirm users pass
		function confirmUserpass($username, $password)
		{
			//add slashes if necessary
			if(!get_magic_quotes_gpc())
			{
				$username = addslashes($username);
			}
			
			//verify that username is in database
			$q = "SELECT password FROM members WHERE username = '$username'";
			$result = mysql_query($q, $this->connection);
			if(!$result || (mysql_num_rows($result) < 1))
			{
				return 1; //indicate username failure
			}
			
			//retrieve password from result, strip slashes
			$dbarray = mysql_fetch_array($result);
			$dbarray['password'] = stripslashes($dbarray['password']);
			$password = stripslashes($password);
			
			//validate that password is correct
			if($password == $dbarray['password'])
			{
				return 0; //success! username and password confirmed
			}
			else 
			{
				return 2; //indicate password failure
			}
		}
		
		//confirm userid
		function confirmUserID($username, $userid)
		{
			//add slashes if necessary (for query)
			if(!get_magic_quotes_gpc())
			{
				$username = addslashes($username);
			}
			
			//verify that username is in database
			$q = "SELECT id FROM members WHERE username  = '$username'";
			$result = mysql_query($q, $this->connection);
			if(!$result || (mysql_num_rows($result) < 1))
			{
				return 1; //indicates username failure
			}
			
			//retrieve userid from database, strip slashes
			$dbarray = mysql_fetch_array($result);
			$dbarray['id'] = stripslashes($dbarray['id']);
			$userid = stripslashes($userid);
			
			//validate that userid is correct
			if($userid == $dbarray['id'])
			{
				return 0; //success! username and userid are correct
			}
			else
			{
			 return  2; //indicates userid invalid
		}
	}
	
	//username taken
	function usernameTaken($username)
	{
		if(!get_magic_quotes_gpc())
		{
			$username = addslashes($username);
		}
		$q = "SELECT username FROM members WHERE username = '$username'";
		$result = mysql_query($q, $this->connection);
		return (mysql_num_rows($result) > 0);
	}
	
	//username banned
	function usernameBanned($username)
	{
		if(!get_magic_quotes_gpc())
		{
			$username = addslashes($username);
		}
		$q = "SELECT username FROM members WHERE username = '$username'";
		$result = mysql_query($q, $this->connection);
		return (mysql_num_rows($result) > 0);
	}
	
	//add new user
	function addNewUser($username, $password, $email)
	{
		$time = time();
		//if admin sign up give admin user level
		if(strcasecmp($username, ADMIN_NAME) == 0)
		{
			$ulevel = ADMIN_LEVEL;
		}
		else
		{
			$ulevel = USER_LEVEL;
		}
		$q = "INSERT INTO members VALUES ('$username', '$password', '0', $ulevel, '$email', $time)";
		return mysql_query($q, $this->connection);
	}
	//update user field
	function updateUserField($username, $field, $value)
	{
		$q = "UPDATE members SET ".$field." = '$value' WHERE username = '$username'";
		return mysql_query($q, $this->connection);
	}
	
	//get userinfo
	function getUserInfo($username)
	{
		$q = "SELECT * FROM  members WHERE username = '$username'";
		$result = mysql_query($q, $this->connection);
		//error occured, return given name by default
		if(!$result || (mysql_num_rows($result) < 1))
		{
			return NULL;
		}
		//return result array
		$dbarray = mysql_fetch_array($result);
		return $dbarray;
	}
	
	//getnumMembers
	function getNumMembers()
	{
		if($this->num_members < 0)
		{
			$q = "SELECT * FROM members";
			$result = mysql_query($q, $this->connection);
			$this->num_members = mysql_num_rows($result);
		}
		return $this->num_members;
	}
	
	//calcnumactiveusers
	function calcNumActiveUsers()
	{
		$q = "SELECT * FROM active_users";
		$result = mysql_query($q, $this->connection);
		$this->num_active_users = mysql_num_rows($result);
	}
	
	//calcactiveguests
	function calcNumActiveGuests()
	{
		$q = "SELECT * FROM active_guests";
		$result = mysql_query($q, $this->connection);
		$this->num_active_guests = mysql_num_rows($result);
	}
	
	//addactiveuser
	function addActiveUser($username, $time)
	{
		$q = "UPDATE members SET timestamp = '$time' WHERE username = '$username'";
		mysql_query($q, $this->connection);
		
		if(!TRACK_VISITORS) return;
		$q = "REPLACE INTO active_users VALUES ('$username', '$time')";
		mysql_query($q, $this->connection);
		$this->calcNumActiveUsers();
	}

	//addactiveguests
	function addActiveGuest($ip, $time)
	{
		if(!TRACK_VISITORS) return;
		$q = "REPLACE INTO active_guests VALUES ('$ip, '$time')";
		mysql_query($q, $this->connection);
		$this->calcNumActiveGuests();
	}
	
	//remove active users
	function removeActiveUser($username)
	{
		if(!TRACK_VISITORS) return;
		$q = "DELETE FROM ACTIVE_USERS WHERE username = '$username'";
		mysql_query($q, $this->connection);
		$this->calcNumActiveUsers();
	}
	
	//remove active guests
	function removeActiveGuest($ip)
	{
		if(!TRACK_VISITORS) return;
		$q = "DELETE FROM ACTIVE_GUESTS WHERE ip = '$ip'";
		mysql_query($q, $this->connection);
		$this->calcNumActiveGuests();
	}
	
	//remove Inactiveusers
	function removeInactiveUsers()
	{
		if(!TRACK_VISITORS) return;
		$timeout = time()-USER_TIMEOUT*60;
		$q = "DELETE FROM ACTIVE_USERS WHERE timestamp < $timeout";
		mysql_query($q, $this->connection);
		$this->calcNumActiveUsers();
	}
	
	//remove inactiveguests
		function removeInactiveGuests()
	{
		if(!TRACK_VISITORS) return;
		$timeout = time()-GUEST_TIMEOUT*60;
		$q = "DELETE FROM ACTIVE_GUESTS WHERE timestamp < $timeout";
		mysql_query($q, $this->connection);
		$this->calcNumActiveGuests();
	}
	
	//query - performs the given query on the database and returns the result which may be false or true or 
	//a resource identifier
	function query($query)
	{
		return mysql_query($query, $this->connection);
	}
	};
	
	
	//create database connection
	$database = new MySQLDB;
	
	
		
?>

any help will be appreciated thanks
AnswerRe: mysql_query error Pin
Gerben Jongerius8-Feb-11 4:13
Gerben Jongerius8-Feb-11 4:13 
Questiondisplay query result in a table using PHP Pin
PermissionDenied6-Feb-11 21:10
PermissionDenied6-Feb-11 21:10 
AnswerRe: display query result in a table using PHP Pin
Jules VDV9-Feb-11 5:56
Jules VDV9-Feb-11 5:56 
AnswerRe: display query result in a table using PHP Pin
Al4211-Feb-11 13:02
Al4211-Feb-11 13:02 
Questionmake tab&menu Pin
Elham M5-Feb-11 6:59
Elham M5-Feb-11 6:59 
AnswerRe: make tab&menu Pin
Eddy Vluggen19-Feb-11 4:05
professionalEddy Vluggen19-Feb-11 4:05 
QuestionProblem with PHP - FastCGI - Headers Pin
Lea Hayes4-Feb-11 14:51
Lea Hayes4-Feb-11 14:51 
AnswerRe: Problem with PHP - FastCGI - Headers Pin
Peter_in_27804-Feb-11 15:25
professionalPeter_in_27804-Feb-11 15:25 
GeneralRe: Problem with PHP - FastCGI - Headers Pin
Lea Hayes5-Feb-11 4:30
Lea Hayes5-Feb-11 4:30 
GeneralRe: Problem with PHP - FastCGI - Headers Pin
Peter_in_27806-Feb-11 14:40
professionalPeter_in_27806-Feb-11 14:40 
GeneralRe: Problem with PHP - FastCGI - Headers Pin
Lea Hayes7-Feb-11 1:26
Lea Hayes7-Feb-11 1:26 
AnswerRe: Problem with PHP - FastCGI - Headers Pin
Peter_in_27807-Feb-11 13:28
professionalPeter_in_27807-Feb-11 13:28 
GeneralRe: Problem with PHP - FastCGI - Headers Pin
Lea Hayes7-Feb-11 14:09
Lea Hayes7-Feb-11 14:09 
AnswerRe: Problem with PHP - FastCGI - Headers Pin
Peter_in_27807-Feb-11 15:00
professionalPeter_in_27807-Feb-11 15:00 
GeneralRe: Problem with PHP - FastCGI - Headers Pin
Lea Hayes8-Feb-11 1:11
Lea Hayes8-Feb-11 1:11 
GeneralRe: Problem with PHP - FastCGI - Headers Pin
nickmaroulis8-Feb-11 10:36
nickmaroulis8-Feb-11 10:36 
GeneralRe: Problem with PHP - FastCGI - Headers Pin
Lea Hayes8-Feb-11 16:14
Lea Hayes8-Feb-11 16:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.