Jump to content

write to mysql- email activation


mingger

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/251968-write-to-mysql-email-activation/
Share on other sites

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.