mingger Posted November 28, 2011 Share Posted November 28, 2011 Hey php gods! I recently watched a tutorial on how to make a membership system, it all turned out fine n stuff. So i wanted to expand and i found out a way to make a email activation "thingie", by making 2 new rows. 1 called email_code and a second called email_a(a for activate). When the person then registered, he woulld get a email where he should go to a link and write a code that was generate with a rand fuction and placed in the email_code row in the database. Then when the person wrote his username and the code in a form from the link in the email, the email_a would change from 0 to 1 if the username matched to the code he got. (sry for bad english). anyway here is the code: <!DOCTYPE html> <html> <head> <link href="style.css" type="text/css"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Activate email</title> </head> <body> <form action="" method="POST"> Username:<input type="text" name="username"> Code:<input type="text" name="activate"> <input type="submit" name="submit" value="aktiver"> </form> <?php include 'connect.php'; $username = $_POST('username'); $activate = $_POST('activate'); $submit = $_POST('submit'); $query = mysql_query("SELECT username AND email_code FROM user"); while ($row = mysql_fetch_assoc($query)){ $dbusername = $row['username']; $dbcode = $row['email_code']; } if ($_POST['submit']){ if ($username==$dbusername&&$code==$dbcode){ mysql_query("UPDATE users SET email_a = '1' WHERE username = '$username' AND email_code = '$activate'"); echo "Du er blevet aktiveret"; } else echo "Forkert data"; } else ?> </body> </html> Hope you can help me MinG Quote Link to comment https://forums.phpfreaks.com/topic/251968-write-to-mysql-email-activation/ Share on other sites More sharing options...
guinbRo Posted November 28, 2011 Share Posted November 28, 2011 Well I'm not sure what you're question is specifically, but I can tell you that you have an extra "else". While this probably isn't throwing an error, it's kind of an eye sore. if ($username==$dbusername&&$code==$dbcode){ mysql_query("UPDATE users SET email_a = '1' WHERE username = '$username' AND email_code = '$activate'"); echo "Du er blevet aktiveret"; } else echo "Forkert data"; } else Could be if ($_POST['submit']){ if($username == $dbusername && $code == $dbcode) { mysql_query("UPDATE users SET email_a = '1' WHERE username = '$username' AND email_code = '$activate'") or die("Error updating" . mysql_error()); } else { //Display error message } } This way is a bit clearner, and adding the die will help you determine if it is successfully updating on the query. Quote Link to comment https://forums.phpfreaks.com/topic/251968-write-to-mysql-email-activation/#findComment-1291925 Share on other sites More sharing options...
mingger Posted November 28, 2011 Author Share Posted November 28, 2011 Hey Thank you for helping. Im sorry for not saying the error, that was kinda dum Its not writing any errors back or anything when i press the submit button, and it does not change the email_a... Quote Link to comment https://forums.phpfreaks.com/topic/251968-write-to-mysql-email-activation/#findComment-1291943 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.