Irresistable Posted November 3, 2009 Share Posted November 3, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180129-solved-how-do-i-change-this-to-an-if-statement/ Share on other sites More sharing options...
marcus Posted November 3, 2009 Share Posted November 3, 2009 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/180129-solved-how-do-i-change-this-to-an-if-statement/#findComment-950228 Share on other sites More sharing options...
Irresistable Posted November 3, 2009 Author Share Posted November 3, 2009 Thanks. I'll test it out now. Seems a strange format to do it, but I'll test it. Should I include the session.php and constants.php Quote Link to comment https://forums.phpfreaks.com/topic/180129-solved-how-do-i-change-this-to-an-if-statement/#findComment-950250 Share on other sites More sharing options...
mikesta707 Posted November 3, 2009 Share Posted November 3, 2009 if you are using variables or functions from those pages than yes Quote Link to comment https://forums.phpfreaks.com/topic/180129-solved-how-do-i-change-this-to-an-if-statement/#findComment-950254 Share on other sites More sharing options...
Irresistable Posted November 3, 2009 Author Share Posted November 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180129-solved-how-do-i-change-this-to-an-if-statement/#findComment-950259 Share on other sites More sharing options...
mikesta707 Posted November 3, 2009 Share Posted November 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/180129-solved-how-do-i-change-this-to-an-if-statement/#findComment-950262 Share on other sites More sharing options...
marcus Posted November 3, 2009 Share Posted November 3, 2009 My mistake, sorry about that mix up. Quote Link to comment https://forums.phpfreaks.com/topic/180129-solved-how-do-i-change-this-to-an-if-statement/#findComment-950264 Share on other sites More sharing options...
Irresistable Posted November 3, 2009 Author Share Posted November 3, 2009 Cheers, that helped alot! Quote Link to comment https://forums.phpfreaks.com/topic/180129-solved-how-do-i-change-this-to-an-if-statement/#findComment-950271 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.