...

View Full Version : Disable user account help



PRodgers4284
03-15-2008, 04:33 PM
I am working on a basic admin area for a website, im want to be able to disable user accounts. I have a field in the database table called "active" which stores a 1 if the user is active or a 0 if the account is inactive. I have the following code that i want to set the active field to "0" to disable the user account, but im not sure of the query is correct:

The query is:


<?php

$username = $_GET['username'];

if (isset($_POST['submit'])) {

mysql_query("UPDATE users SET active='0' WHERE username=$username");
?>

InsaneRhino
03-15-2008, 04:45 PM
That would work fine. Just close the if statement.
<?php

$username = $_GET['username'];

if (isset($_POST['submit'])) {

mysql_query("UPDATE users SET active='0' WHERE username=$username");
}
?>

PRodgers4284
03-15-2008, 05:42 PM
That would work fine. Just close the if statement.
<?php

$username = $_GET['username'];

if (isset($_POST['submit'])) {

mysql_query("UPDATE users SET active='0' WHERE username=$username");
}
?>


Hey thanks for the reply, yeah it worked ok, but i now need to be able to enable the user account, I thought it was just a matter of changing the "0" to a "1" but it doesnt same to update the table in the database.


$username = $_GET['username'];

if (isset($_POST['submit'])) {

mysql_query("UPDATE users SET active='1' WHERE username=$username");
?>

InsaneRhino
03-15-2008, 06:11 PM
It is that simple, that if statement is still open though. Is it that?

PRodgers4284
03-15-2008, 06:24 PM
It is that simple, that if statement is still open though. Is it that?

Hey this is my full php code, i still doesnt work properly


<?php

$username = $_GET['username'];

if (isset($_POST['submit'])) {

mysql_query("UPDATE users SET active='1' WHERE username=$username");


//Send out email

require_once('class.phpgmailer.php');
$mail = new PHPGMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = 'ssl://smtp.gmail.com'; // SMTP servers
$mail->FromName = 'Jobs4U.com';
$mail->AddAddress($email);
$mail->Subject = 'Jobs4U User Account';
$mail->Body = "Your account with the following details:\n\nUsername: $username\nEmail: $email\nForename: $forename\nSurname: $surname\nLocation: $location\n\nhas been disabled.\n\n";

$mail->Send();

?>

<br />
<a href="index.php">Back to main page</a>
<br />
<br />
<br />
The account for <b><?php echo $username; ?></b> has been disabled.

<?php
}
else
{
$account = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='$username'"));
?>

PappaJohn
03-15-2008, 07:05 PM
First of all, you have no error checking / recovery logic for your queries. You execute a query and your code continues on blindly, without regard for whether the query failed or not.

As a first step, I'd suggest implementing proper error checking / recovery. The php manual has examples, and the pages of this forum have countless examples of proper error management.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum