Jump to content

[SOLVED] How do I change this to an IF statement?


Irresistable

Recommended Posts

What I am trying to do.. is;

Look in the database for activated=2 - If its activated=1, then activate the account (it shows below changing activated=1 to 2) though I want to check that if in the database shows activated=2 then it'll show a message = "This email has already been activated"

It'd be on the format of..

 

If activated = 1

Check for invalid code,

If code is valid etc, then activate email and set activated to 2

 

If activated = 2

show error; this email has already been activated.

 

Or something similar.. may need an else statement in there too. I'm not too sure what to do. Anyone help? Here is the activate.php without checking if the account is activated. (There for.. if the activation key is valid.. everytime you click on the activation link, it'll always say the account is activated instead of saying it's already activated)

 

 

<?php 
include ('include/session.php');
include ('include/constants.php'); 
if (!isset($_GET['email']) && !isset($_GET['activationkey']) )
{
$msg = "ERROR: Invalid code...";
exit();
}
$rsCode = mysql_query("SELECT activ_code from emails where email='$_GET[email]'") or die(mysql_error());
list($acode) = mysql_fetch_array($rsCode);
if ($_GET['activationkey'] == $acode)
{
mysql_query("update emails set activated=2 where email='$_GET[email]'") or die(mysql_error());
echo "<h3>Thank you </h3>Email confirmed and account activated. You are now subscribed to the Developers Community newsletter!";
} else
{ echo "ERROR: Incorrect activation"; }
?>

Link to comment
Share on other sites

Something like so?

 

<?php
$sql = "SELECT activ_code,activated FROM `emails` WHERE `email`='".mysql_real_escape_string($_GET['email'])."'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
$act = $row['activated'];
$acode = $row['activ_code'];
$code = $_GET['activationkey'];

switch($act){
case 1:
	if($acode == $code){
		// success!
		$sql2 = "UPDATE `emails` SET `activated` = 1 WHERE `email`='".mysql_real_escape_string($_GET['email'])."'";
		$res2 = mysql_query($sql2) or die(mysql_error());
		$output = "Your email has successfully been activated!";
	}else {
		$output = "Invalid activation code!";
	}
break;

case 2:
	$output = "Your email has already been activated, please continue to the site!";
break;

default:
	$output = "Something went wrong...";
}

echo $output;
?>

Link to comment
Share on other sites

I included the session.php and constants.php

Theres a fault in the code, theres no error, but when it says that "your email has been activated"

It doesn't change the collumn "activated" from 1, to 2.

 

It works apart from that, as when it shows "1" in the collum activated, it knows to activate it.. though doens't change it to "2" though if I manually change it to "2" and click on the activation link, it does display that its already been activated.

Link to comment
Share on other sites

right here

switch($act){
   case 1:
      if($acode == $code){
         // success!
         $sql2 = "UPDATE `emails` SET `activated` = 1 WHERE `email`='".mysql_real_escape_string($_GET['email'])."'";

 

probably want that update to set activated=2 instead of 1

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.