codingdreamer Posted June 18, 2013 Share Posted June 18, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/279294-help-email-activation-function-bug/ Share on other sites More sharing options...
doddsey_65 Posted June 18, 2013 Share Posted June 18, 2013 <td>Code:</td> <td><input type='text' name='user' value='$getcode' /></td> Shouldnt that input name be "code"? Quote Link to comment https://forums.phpfreaks.com/topic/279294-help-email-activation-function-bug/#findComment-1436535 Share on other sites More sharing options...
codingdreamer Posted June 18, 2013 Author Share Posted June 18, 2013 <td>Code:</td> <td><input type='text' name='user' value='$getcode' /></td> Shouldnt that input name be "code"? Hi Doddsey_65, not necessarily--it's the name of the table cell and does not have to be surrounded by quotations. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/279294-help-email-activation-function-bug/#findComment-1436599 Share on other sites More sharing options...
mac_gyver Posted June 18, 2013 Share Posted June 18, 2013 what he means is, your form has two fields with the same name='user' attribute and the one for the $getcode value should have the name='code' Quote Link to comment https://forums.phpfreaks.com/topic/279294-help-email-activation-function-bug/#findComment-1436600 Share on other sites More sharing options...
Solution codingdreamer Posted June 18, 2013 Author Solution Share Posted June 18, 2013 ahhh...It works! Thank you both for your help. Quote Link to comment https://forums.phpfreaks.com/topic/279294-help-email-activation-function-bug/#findComment-1436611 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.