so i have followed this tutorial and i stuck into the activate section of this
here's the tutorial. what went wrong?
http://youhack.me/2010/04/01/building-a-registration-system-with-email-verification-in-php/comment-page-3/

Recommended Answers

All 26 Replies

What happened? Do you get errors? Be more specific, we cannot just guess what's wrong without knowing/seeing what you have done.

so i have this in my index.php

    <div id="content" style="margin-bottom:100px;">
<form action="index.php" method="post" class="registration_form">
  <fieldset>
    <legend>Registration Form </legend>

    <p>Create A new Account <span style="background:#EAEAEA none repeat scroll 0 0;line-height:1;margin-left:210px;;padding:5px 7px;">
Already a member? <a class="black" href="login.php">Log in</a></span> </p>

    <div class="elements">
      <label for="name">Name :</label>
      <input type="text" id="name" name="name" size="25" />
    </div>
    <div class="elements">
      <label for="e-mail">E-mail :</label>
      <input type="text" id="e-mail" name="e-mail" size="25" />
    </div>
    <div class="elements">
      <label for="Password">Password:</label>
      <input type="password" id="Password" name="Password" size="25" />
    </div>
    <div class="submit">
     <input type="hidden" name="formsubmitted" value="TRUE" />
      <input type="submit" value="Register" />
    </div>
  </fieldset>
</form>
<?php
include ('db_con.php');
if (isset($_POST['formsubmitted'])) {
    $error = array(); //Declare An Array to store any error message
    if (empty($_POST['name'])) { //if no name has been supplied
        $error[] = 'Please Enter a name '; //add to array "error"
    } else {
        $name = $_POST['name']; //else assign it a variable
    }

    if (empty($_POST['e-mail'])) {
        $error[] = 'Please Enter your Email ';
    } else {

        if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",
            $_POST['e-mail'])) {
            //regular expression for email validation
            $Email = $_POST['e-mail'];
        } else {
            $error[] = 'Your EMail Address is invalid  ';
        }

    }

    if (empty($_POST['Password'])) {
        $error[] = 'Please Enter Your Password ';
    } else {
        $Password = $_POST['Password'];
    }

    if (empty($error)) //send to Database if there's no error '

    { // If everything's OK...

        // Make sure the email address is available:
        $query_verify_email = "SELECT * FROM members  WHERE Email ='$Email'";
        $result_verify_email = mysqli_query($dbc, $query_verify_email);
        if (!$result_verify_email) { //if the Query Failed ,similar to if($result_verify_email==false)
            echo ' Database Error Occured ';
        }

        if (mysqli_num_rows($result_verify_email) == 0) { // IF no previous user is using this email .

            // Create a unique  activation code:
            $activation = md5(uniqid(rand(), true));

            $query_insert_user =
                "INSERT INTO `members` ( `Username`, `Email`, `Password`, `Activation`) VALUES ( '$name', '$Email', '$Password', '$activation')";

            $result_insert_user = mysqli_query($dbc, $query_insert_user);
            if (!$result_insert_user) {
                echo 'Query Failed ';
            }

            if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull.

                // Send the email:
                $message = " To activate your account, please click on this link:\n\n";
                $message .= WEBSITE_URL . 'activate.php?email=' . urlencode($Email) . "&key=$activation";
                mail($Email, 'Registration Confirmation', $message, 'From:'.EMAIL);

                // Flush the buffered output.

                // Finish the page:
                echo '<div class="success">Thank you for
registering! A confirmation email
has been sent to ' . $Email .
                    ' Please click on the Activation Link to Activate your account </div>';

            } else { // If it did not run OK.
                echo '<div class="errormsgbox">You could not be registered due to a system
error. We apologize for any
inconvenience.</div>';
            }

        } else { // The email address is not available.
            echo '<div class="errormsgbox" >That email
address has already been registered.
</div>';
        }

    } else { //If the "error" array contains error msg , display them

        echo '<div class="errormsgbox"> <ol>';
        foreach ($error as $key => $values) {

            echo '  <li>' . $values . '</li>';

        }
        echo '</ol></div>';

    }

    mysqli_close($dbc); //Close the DB Connection

} // End of the main Submit conditional.


?>

and the db_con.php contents are:

<?php

/*Define constant to connect to database */
DEFINE('DATABASE_USER', 'user');
DEFINE('DATABASE_PASSWORD', 'password');
DEFINE('DATABASE_HOST', 'localhost');
DEFINE('DATABASE_NAME', 'name');
/*Default time zone ,to be able to send mail */
date_default_timezone_set('UTC');

/*You might not need this */
ini_set('SMTP', "mail.myt.mu");
// Overide The Default Php.ini settings for sending mail

//This is the address that will appear coming from ( Sender )
define('EMAIL', 'email@gmail.com');

/*Define the root url where the script will be found such as
http://website.com or http://website.com/Folder/ */
DEFINE('WEBSITE_URL', 'http://www.jocurigratisonlinenet.ro/registration/');

// Make the connection:
$dbc = @mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD,
 DATABASE_NAME);

if (!$dbc) {
 trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}

?>

i get the activation link but when i click it it takes me to activate.php
and get this error "Oops !Your account could not be activated. Please recheck the link or contact the system administrator."
here's the contents of activate.php

<?php
include ('db_con.php');
if (isset($_GET['email']) && preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/',
 $_GET['email'])) {
 $email = $_GET['email'];
}
if (isset($_GET['key']) && (strlen($_GET['key']) == 32))
 //The Activation key will always be 32 since it is MD5 Hash
 {
 $key = $_GET['key'];
}

if (isset($email) && isset($key)) {

 // Update the database to set the "activation" field to null

 $query_activate_account = "UPDATE members SET Activation=NULL WHERE(Email ='$email' AND Activation='$key')LIMIT 1";
 $result_activate_account = mysqli_query($dbc, $query_activate_account);

 // Print a customized message:
 if (mysqli_affected_rows($dbc) == 1) //if update query was successfull
 {
 echo '<div>Your account is now active. You may now <a href="login.php">Log in</a></div>';

 } else {
 echo '<div>Oops !Your account could not be activated. Please recheck the link or contact the system administrator.</div>';

 }

 mysqli_close($dbc);

} else {
 echo '<div>Error Occured .</div>';
}
?>

Echo the query you run, and run it with phpMyAdmin. Perhaps you have either no matching rows, or multiple matching rows.

when i run

"UPDATE members SET Activation=NULL WHERE(Email ='some@email.com' AND Activation='s0m3k3y')LIMIT 1"

it says "Affected rows: 0 (Query took 0.00001 sec)

this is what i get after echoing on activate.php

UPDATE members SET Activation=NULL WHERE(Email ='andrei_3333333333@yahoo.com' AND Activation='8f979bda59ba8c10b3eb8b1d03b7f7ce')LIMIT 1

Oops !Your account could not be activated. Please recheck the link or contact the system administrator.

Run this query in phpMyAdmin, see what happens. Perhaps it triggers an error. Check if these values match in your table.

maybe i screwed with the database table i have inserted it in a query

no there isn't

says
Affected rows: 0 (Query took 0.0001 sec)
SQL query:

UPDATE members SET Activation = NULL WHERE (
    Email = 'gffg@hhh.com' AND Activation = '657t67tr67t76t'
) LIMIT 1 

Are you sure you're on the right database? That's the only thing I can think of. Other than that, I'm out of ideas.

the connection is right otherwise i would get errors

can you test this on your own?

Have you cheched if the new user is succesfull inserted into the database (before the activation step)?

yes it is

can you test this on your own?

Only if you give a mysqldump of your database.

how to do that? export?

Yes, phpMyAdmin has an export option. The members table should suffice.

and give a link to my site for you to download it?

i have as txt this editor doesn't allow as sql

See your attached file. You tried to validate andrei_3333333333@yahoo.com but in your table it is andrei_3333333333@ya, because the email column is only 20 characters. That's the reason the row is not found.

so i have to alter the length value in order to allow me to register?

Yes. 20 characters for an email address is rather short.

it's working thanks a lot you deserve a beer:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.