Jump to content

HELP! Email activation function bug


codingdreamer
Go to solution Solved by codingdreamer,

Recommended Posts

Hello All,

 

I'm having difficulty figuring out why my activation page isn't responding correctly. When I click on a link to activate my test account, the function takes me to the site with the right information populated in the text box; however, when I go to submit, it triggers an else function instead of the if function (to activate the account). I've tried changing   $getuser = $_GET['user'] to $_POST but no luck thus far. Any help/insights would be greatly appreciated! Thanks.

 

 

 

When I click on the link to activate I get this (example screenshot):

 

Username: test

Code: afcadjijckack

 

[Activate button]

 

 

Upon clicking on the 'Activate' button, I get this (example screenshot):

 

You must enter your code

 

Username: afcadjijckack

Code: (blank)

 

[Activate button]

 

 

Here's my code:

<?php 
error_reporting (E_ALL^E_NOTICE);
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Activate Your Account</title>
</head>
<body>

<?php 

	$getuser = $_GET['user'];
	$getcode = $_GET['code'];
	
	
	if ( $_POST['activatebtn'] ) {
		$getuser = $_POST['user'];
		$getcode = $_POST['code'];
		
		if ($getuser){
			if ($getcode){
				require("./connect.php");
				
				$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
				$numrows = mysql_num_rows($query);
				if ($numrows == 1){
					$row = mysql_fetch_assoc($query);
					$dbcode = $row['code'];
					$dbactive = $row['active'];
					
					if($dbactive == 0){
						if($dbcode == $getcode) {
							mysql_query("UPDATE users SET active='1' WHERE username='$getuser'" );
							$query = mysql_query("SELECT * FROM users WHERE username='$getuser' AND active='1' ");
							$numrows = mysql_num_rows($query);
							
							if($numrows == 1) {
								$errormsg = "Your account has been activated. You may now login.";
								$getuser = "";
								$getcode = "";
							}
							else
								$errormsg = "An error has occured. Your account was not activated.";
						}
						else
							$errormsg = "your code is incorrect.";
					
					}
					else
						$errormsg = "This account is already active.";
				
				}
				else
					$errormsg = "The username you entered was not found.";
				
				mysql_close();
			}
			else
				$errormsg = "You must enter your code.";
		
		}
		else
			$errormsg = "You must enter your username.";
	}
	else
		$errormsg= "";
	
	
		echo "<form action='./activate.php' method='post'>
		<table>
		<tr>
			<td>$errormsg</td>
		</tr>
		<tr>
			<td>Username:</td>
			<td><input type='text' name='user' value='$getuser' /></td>
		</tr>
		<tr>
			<td>Code:</td>
			<td><input type='text' name='user' value='$getcode' /></td>
		</tr>
		<tr>
			<td></td>
			<td><input type='submit' name='activatebtn' value='Activate' /></td>
		</tr>
		</table>
		</form>";
?>

</body>
</html>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.