3 Replies - 432 Views - Last Post: 10 August 2010 - 08:28 PM Rate Topic: -----

#1 CodeVillain  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 143
  • Joined: 10-July 10

PHP/MySQL banned user trouble

Posted 10 August 2010 - 06:37 PM

So, I decided it would be wise to create a means of suspending/deactivating accounts. I figured a simple way to do this would be to create an "active" column in the member's table of my database that had either the values of "0" (active) or "1" (inactive)

So, I figured I would just implement a check into the login system preventing them from logging in if their account is deactivated, so I did this....

(Note: the database connection is already established)


$login = clean($_POST['login']);
	$password = clean($_POST['password']);

	$qry="SELECT active FROM members WHERE login='$login'";
	$active=mysql_query($qry);
	if($active == 1) {
	header("location: deactivated.php");
	exit();
	}


I of course put that before the code that logs them in, yet deactivated accounts are still logging in...

On the flip side, if I change the if($active == 1) to if($active = 1) then all accounts get redirected to the deactivated page.

Can anyone help shed a little light on this? Am I missing something basic? Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: PHP/MySQL banned user trouble

#2 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: PHP/MySQL banned user trouble

Posted 10 August 2010 - 07:20 PM

$active is a result object, in this instance. You'll need to use a fetching function on it (like, say, mysql_fetch_assoc()).

$login = clean($_POST['login']);
$password = clean($_POST['password']);
$qry = "SELECT active FROM members WHERE login='$login'";
$result = mysql_query($qry);
if(!$result)
{
	error_log(mysql_error());
	die("There was an error with the database.  it has been logged.");
}
$active = mysql_fetch_assoc($result);
if($active['active'] == 1)
{
	header("location: deactivated.php");
	exit();
}

This post has been edited by Valek: 10 August 2010 - 07:21 PM

Was This Post Helpful? 2
  • +
  • -

#3 CodeVillain  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 143
  • Joined: 10-July 10

Re: PHP/MySQL banned user trouble

Posted 10 August 2010 - 07:49 PM

View PostValek, on 10 August 2010 - 05:20 PM, said:

$active is a result object, in this instance. You'll need to use a fetching function on it (like, say, mysql_fetch_assoc()).

$login = clean($_POST['login']);
$password = clean($_POST['password']);
$qry = "SELECT active FROM members WHERE login='$login'";
$result = mysql_query($qry);
if(!$result)
{
	error_log(mysql_error());
	die("There was an error with the database.  it has been logged.");
}
$active = mysql_fetch_assoc($result);
if($active['active'] == 1)
{
	header("location: deactivated.php");
	exit();
}


Works perfectly, thank you very much.
Was This Post Helpful? 0
  • +
  • -

#4 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: PHP/MySQL banned user trouble

Posted 10 August 2010 - 08:28 PM

Anytime :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1