I am doing a piece of programming coursework for my A-Level and I am stuck on a problem. I hope one of you guys can help me.
I am setting up a member sytem, at the moment I am on the email activation stage. Using php and mysqli coding with a connected database, I have been able to set the email activation link to work so that when the user clicks on the activation link, it activates the user’s account by setting the “Active” database field from ‘0’ to ‘1’.
The only problem I have is that if the user clicks on the activation link again in the email, as the user is already active, I want it to display the message “This Account has already been Activated”;. This is so the user cannot activate the account again.
But I cannot get it to display this message. It keeps displaying the message “Account is Activated” even though the user has already activated the account. Does anyone know what I am doing wrong?
Below is my code:
<?php
$user_to_be_activated = $_GET['user'];
$code_to_be_matched = $_GET['code'];
$code_activated = 1;
// don't use $mysqli->prepare here
$query = "SELECT TeacherUsername, Active, Code FROM Teacher WHERE TeacherUsername = ? AND Code = ? ";
// prepare query
$stmt=$mysqli->prepare($query);
// You only need to call bind_param once
$stmt->bind_param("ss",$user_to_be_activated, $code_to_be_matched);
// execute query
$stmt->execute();
// get result and assign variables (prefix with db)
$stmt->bind_result($dbTeacherUsername, $dbActive, $dbCode);
//get number of rows
$stmt->store_result();
$counting = $stmt->num_rows();
if($counting == '1')
{
if($dbActive == '1')
{
echo "This Account has already been Activated";
}
else{
$updatesql = "UPDATE Teacher SET Active = ? WHERE TeacherUsername = ? AND Code = ?";
$update = $mysqli->prepare($updatesql);
$update->bind_param("sss", $code_activated, $user_to_be_activated, $code_to_be_matched);
$update->execute();
$update->close();
echo "Account is Activated";
}
}
else
{
echo "The Code and Username doesn't match! Account is not Activated.";
}
?>
1 Answer