I need help for my code after the user done register for their new account in my system.

Here is the verification link that the user will receive via email for him/her to verified the email:

http://localhost/staff/email_verification.php?activation_code=49024f2e7b8c05dc1g66005g780g6060

But, when the user click on above link, I notice based on my below code yes my staff table status column changed to verified. However at my email_verification.php page its supposed to show message as Your account successfully register and you can start login now but its shows as something went wrong.

If I didnt set my $_GET['activation_code]

Then how come its reacting to my UPDATE statement?

Here is my some of my code from phpmailer:

$activation_code =  md5( rand(0,1000) );

$base_url       = "http://localhost/staff/";
$mail->Body    .= ''.$base_url.'email_verification.php?activation_code='.$activation_code.'<br><br>';

Here is my code for email_verification.php:

please take note I have already tried !empty() function as well

<?php

session_start();
include ('conn.php');

if(isset($_GET['activation_code'])){
  $activation_code = $_GET['activation_code'];
  $resultSet = $db->query("SELECT activation_code, status FROM staff WHERE activation_code = '$activation_code' AND status = 'not verified' LIMIT 1");

  if($resultSet->num_rows == 1){
    $update = $db->query("UPDATE staff SET status = 'verified' WHERE activation_code = '$activation_code' LIMIT 1");

    if($update){
      $_SESSION['can'] = "Your account successfully register and you can start login now";
      echo("<script>window.location = 'email_verification.php';</script>");
    }else{
      echo $db->error;
    }
  }else{
    $_SESSION['no'] = "This URL not valid or already verified";
    echo("<script>window.location = 'email_verification.php';</script>");
  }
}else{
  die("something went wrong");
}

?>

Someone please help me on this, I have been trying this out almost for 3 days, I am not sure where I went wrong?

Based on the code you've provided, it is impossible for the query UPDATE staff SET status = 'verified' WHERE activation_code = '$activation_code' LIMIT 1 to be executed if it's saying "soemthing went wrong" on line 24. Are you sure the status wasn't already set to verified before running the PHP script?

commented: Well, there is nothing wrong with that query and it wasn’t set to verified before its executes.. that “something went wrong” message appeared because +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.