uncfelt1147 Posted November 16, 2012 Share Posted November 16, 2012 I can't seem to get my activation link (code) to properly activate the link. I had a lot of trouble debugging it, but once I finished with that, the code runs through, and it keeps saying, "Your account could not be activated. Please re-check the link or contact the administrator." I can't tell what is failing though? Does my code look alright? I am almost sure that my database is correct. Here is the main body of my code: <?php if (isset($_GET['x'], $_GET['y']) && filter_var($_GET['x'], FILTER_VALIDATE_EMAIL) && (strlen($_GET['y']) == 32 )) { require (MYSQL); $q = "UPDATE users SET active=NULL WHERE email=' " . mysqli_real_escape_string($dbc, $_GET['x']) . "' \n" . "\n" . "AND \n" . " \n" . "active=' " . mysqli_real_escape_string($dbc, $_GET['y']) . "' \n" . "\n" . "LIMIT 1"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { echo "<h3>Your account is now active; log in at any time.</h3>"; } else { echo '<p class="error">Your account could not be activated. Please re-check the link or contact the administrator.</p>'; } mysqli_close($dbc); } else { $url = BASE_URL . '/index.php'; ob_end_clean(); header("Location: $url"); exit(); } ?> I know that my query is written very oddly. I wrote it like that because it kept feeding me errors and I just wanted it to work for now, so I fed it in very discretely. Any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
swisse Posted November 16, 2012 Share Posted November 16, 2012 Hi uncfelt1147, I'm no expert in PHP, just like you I'm a newbie. I find your query statement a little bit long with all those \n's. This is the code from Larry's book: $q = "UPDATE users SET active=NULL WHERE (email='" . mysqli_real_escape_string($dbc, $_GET['x']) . "' AND active='" .mysqli_real_escape_string($dbc, $_GET['y']) . "') LIMIT 1"; I check always with phpMyAdmin that the person I'm activating is recorded in my database. 3 Link to comment Share on other sites More sharing options...
spookie Posted December 2, 2012 Share Posted December 2, 2012 Did you set the value type of the active column in your database is NULL by default? Please check with your PHPmyadmin to see if the column is indeed NULL, or esle, you can never activate the account. Link to comment Share on other sites More sharing options...
ericp Posted April 15, 2013 Share Posted April 15, 2013 Hi, I copy-and-paste the activate.php I indeed received emails with activation links for the first several days. Now. It stops working. And I don't know why? I learned from another post (http://www.larryullman.com/forums/index.php?/topic/1648-chapter-18-registerphp-sendmail/) to add sendmail_path =/usr/sbin/sendmail -t into my .ini file. It still didn't work. I use: Linux share host at godaddy.com PHP version: 5.3.21 Can you help? Eric P Link to comment Share on other sites More sharing options...
HartleySan Posted April 15, 2013 Share Posted April 15, 2013 spookie makes a good point. Make sure that the active column in the users table can actually be set to NULL, as that's not possible for columns by default. You may have to alter the active column in the users table to get things working properly. Also, try echoing out your $q variable to the screen before you execute the query to make sure it's actually what it should be. Lastly, try echoing out the value of mysqli_affected_rows($dbc) to see what it is (because clearly, it's not 1). Link to comment Share on other sites More sharing options...
ericp Posted April 16, 2013 Share Posted April 16, 2013 spookie makes a good point. Make sure that the active column in the users table can actually be set to NULL, as that's not possible for columns by default. You may have to alter the active column in the users table to get things working properly. Also, try echoing out your $q variable to the screen before you execute the query to make sure it's actually what it should be. Lastly, try echoing out the value of mysqli_affected_rows($dbc) to see what it is (because clearly, it's not 1). I can see the root cause now. As I use godaddy.com hosting service, which requires the From email address MSUST be the hosted domain name. The email address does not necessarily need to exist, but there are SPAM filters on the outgoing emails to prevent SPAM and spoofing. Eric P Link to comment Share on other sites More sharing options...
ericp Posted December 14, 2013 Share Posted December 14, 2013 Another curious question about activation code is that I have seen some websites that enable the users to activate their new accounts by entering the random code received via cell phone numbers registered during the 'sign-up' process, which i think that it is quite fast, handy, and even secure (if I were wrong). Have you got any book instructing this, Larry? And do you guys know any resources about this to share? Thanks, Eric Link to comment Share on other sites More sharing options...
Larry Posted December 16, 2013 Share Posted December 16, 2013 I have not written that up, nor have I ever implemented it myself. There are services you can use to send text messages, however. I don't think of this route as fast, but it's certainly more and more common. Don't know any resources about it offhand. Link to comment Share on other sites More sharing options...
rob Posted December 16, 2013 Share Posted December 16, 2013 I've used Twilio with both php and ruby - the api is insanely easy to use. There's some good info in the docs as well as many free tutorials on blogs etc. Link to comment Share on other sites More sharing options...
Recommended Posts