chocopi Posted May 12, 2007 Share Posted May 12, 2007 When my users register on my site they recieve an activation email. i was wondering, how do i make so there is a link in the email that when the user clicks it, it changes their active satus from 0 to 1. Many Thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/ Share on other sites More sharing options...
taith Posted May 12, 2007 Share Posted May 12, 2007 on your database, put a `key` field, with a random based string... and a `activated` field, so when you send them an email, it has a link with that random based string, goes to the database, and activates the account with that key :-) Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251437 Share on other sites More sharing options...
paul2463 Posted May 12, 2007 Share Posted May 12, 2007 have an activation.php page which only has one task $code = $_GET['code']; $query = "SELECT * FROM tablename WHERE activationcode = $code"; $result = mysql_query($query) or die ("Error in query" . mysql_query()); $row = mysql_fetch_assoc($result); if (mysql_num_rows($result) == 1) { $id = $row['idtable']; $update = "UPDATE tablename SET active =1 WHERE idtable = '$id'"; mysql_query($update) or die ("Error in query" . mysql_query()); echo "Your account is now active"; header(location: where you need it to be forwarded to; exit; } else { header(location: login page); } then in the email have the activation number be a link to this page setting itself as the code part of the address hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251442 Share on other sites More sharing options...
chocopi Posted May 12, 2007 Author Share Posted May 12, 2007 Thanks for your help !!! but i cant seem to get the code to work, what should the link be. should it be root/activation.php or root/activation/ Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251490 Share on other sites More sharing options...
chocopi Posted May 12, 2007 Author Share Posted May 12, 2007 as i couldnt get yours to work i improvised with this: $activate = $_GET['activate']; $query = "SELECT active FROM users WHERE code = $activate"; if ($query == 0) { $update = "UPDATE users SET active =1 WHERE code = $activate"; mysql_query($update) or die ("Error in query" . mysql_query()); print ("<br /> \n"); print ("<center> \n"); print ("$username, your account is now active, please login on the homepage. \n"); print ("<br /> \n"); print ("<br /> \n"); print ("<a href=\"index.php\">Home Page</a> \n"); print ("</center> \n"); } But for some reason i keep getting an error. any help would be greatly appreciated. ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251515 Share on other sites More sharing options...
Broniukas Posted May 12, 2007 Share Posted May 12, 2007 what error exacly did u get? Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251524 Share on other sites More sharing options...
chocopi Posted May 12, 2007 Author Share Posted May 12, 2007 i get a query error from mysql_query($update) or die ("Error in query" . mysql_query()); so it just says "Error in query" Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251534 Share on other sites More sharing options...
Broniukas Posted May 12, 2007 Share Posted May 12, 2007 just put some quotes $update = "UPDATE users SET active ='1' WHERE code = '$activate'"; Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251537 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Share Posted May 12, 2007 i get a query error from mysql_query($update) or die ("Error in query" . mysql_query()); so it just says "Error in query" shouldn't it be mysql_error() instead of mysql_query() , for it to display the error Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251540 Share on other sites More sharing options...
chocopi Posted May 12, 2007 Author Share Posted May 12, 2007 @Broniukas: im still getting the same error @eZe616: will that make a big difference Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251542 Share on other sites More sharing options...
Broniukas Posted May 12, 2007 Share Posted May 12, 2007 try to change mysql_query($update) or die (mysql_error()); and you will find out whats wrong Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251549 Share on other sites More sharing options...
chocopi Posted May 12, 2007 Author Share Posted May 12, 2007 Thanks for your help. you wouldnt believe it but i forgot to add the page_header so it wasnt connecting to the database however, its still not working properly as it is not picking up the username variable or the the actual activation variable. i think it might be because i am just loading activation.php as i dont know how to get it to work when its activation/ please help, thanks ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251556 Share on other sites More sharing options...
Broniukas Posted May 12, 2007 Share Posted May 12, 2007 dont forget to click SOLVED Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251560 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 yea but its not working. if you could, can you tell how i can get it to recognise that it is the user. the way i would like it to work is that the user clicks on the link root/activation/ it loads up the activation page and activaters their account Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251840 Share on other sites More sharing options...
paul2463 Posted May 13, 2007 Share Posted May 13, 2007 for that to happen then the link they click must also pass either their activation code in the url such as location.href="http://www.yourPage.com/activate.php?code=123456789"; where 123456789 is the activation code you emailed them, then using something like the code I sent originally (admittedly flawed with mysql_query() instead of mysql_error()) which searches the table for that code, pulls the id and updates the the table with the user in it to 'active' for that id. Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-251898 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 Thanks as im still a n00b with php would be possible if you could write something for me? if you can then the activation code would be $activation table would be 'users' and the coloum to update would be 'active' Many thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-252003 Share on other sites More sharing options...
paul2463 Posted May 13, 2007 Share Posted May 13, 2007 <?php $activation = $_GET['activation']; //get the activation code from the url $query = "SELECT * FROM users WHERE activationcode = '$activation'"; //first see if it is a real activation code $result = mysql_query($query) or die ("Error in query" . mysql_error()); $row = mysql_fetch_assoc($result); if (mysql_num_rows($result) == 1) //if one row is returned then it is real { $id = $row['idtable']; //get the id of the table for that activation code $update = "UPDATE users SET active=1 WHERE idusers = '$id'"; mysql_query($update) or die ("Error in query" . mysql_error()); header(location: ; //send them to the page you want them as an active user exit; } else { header(location: ; //send them where you want them to go as a none active user exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-252105 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 wow thanks, but it is saying there is an parse error in header(location: index.php); Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-252119 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php header("Location: index.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-252126 Share on other sites More sharing options...
paul2463 Posted May 13, 2007 Share Posted May 13, 2007 Have a look <a href="http://uk3.php.net/header"> HERE AT THE MANUAL </a> the third grey block from the top gives you the syntax for it Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-252127 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 kool thanks guys, sorry about that. i was unaware of ze quotation marks Quote Link to comment https://forums.phpfreaks.com/topic/51085-solved-email-account-activation/#findComment-252134 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.