Basically I'm making a script that sends the user an email on register and they have to click a link in the email to activate their account.
But in my activate page their seems to be an error in my coding and I've checked it over but I can't find it. I'm sure I'm missing something.
There's no php error as such it's just echoing out the wrong thing and not executing the right thing.
Here's the code...
<?php
//start session
ob_start();
session_start();
//set variables from URL
$id = $_GET['id'];
$activationcode = $_GET['activationcode'];
//connect to the database
include_once"../../connect.php";
//if user already logged in, redirect to the members page
if(isset($_SESSION['username']) || isset($_SESSION['password'])){
header("Location: /members");
}else{
//if variable(s) = NULL
if($id == NULL OR $activationcode == NULL){
$final_report.="Sorry there was an error in activating your account.";
}else{
//if the username doesn't exist, echo error
$check_id = mysql_query("SELECT * FROM `members` WHERE `id` = '$id'") or die(mysql_error());
if(mysql_num_rows($check_id) != 1){
$final_report.="That user does not exist";
}else{
//if already activated, echo error
$get_user_data = mysql_fetch_array($check_id);
if($get_user_data['activated'] == 1){
$final_report.="It seems your account is already activated. Please <a href='/login'>Login</a>.";
}else{
//if activation code does not match, echo error
//THIS SEEMS TO BE WHERE THE ERROR IS
$get_user_data = mysql_fetch_array($check_id);
if($get_user_data['activationcode'] != $activationcode){
$final_report.="Sorry that activation code seems to be invaid.";
}else{
//THIS SEEMS TO BE WHERE THE ERROR IS^
//if activate user
$activate_user = mysql_query("UPDATE `members` SET activated='1' WHERE id='$id'");
$final_report.="Your account has been activated, now you may <a href='/login'>Login</a>.";
}}}}}
?>
<html>
<head>
<title>Activate account</title>
</head>
<body>
<?php
if(!isset($_GET['id']))
{
?>
Sorry there was an error in activating your account.
<?php
}
else
{
echo "".$final_report."";
}
?>
</body>
</html>
*Note I removed the unimportant html.
And I've checked the email send and the activation code does match the one in the database.
Hope you can help.
Thanks in advance,
- Tim.