Error in my activation.php script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gimpact
Forum Commoner
Posts: 65
Joined: Tue Jun 16, 2009 11:08 pm

Error in my activation.php script

Post by gimpact »

Hi,
I am having a tough time with this activation code of mine. My registration script sends email with the activation link

here is an example of the activation link:

Code: Select all

http://www.domain.com/fun/account/activ ... e=65464049
Here is my activation script:

Code: Select all

<?php
 
// Read url
$email = $_GET['email'];
$code = $_GET['code'];
 
// Open database connection
include ("dbConnect.php");
 
// Prepare statement
$sql = "SELECT * FROM userdata WHERE email='$email' AND activationpassword='$code'";
 
// Execute statement
$result = mysql_query($mysql) or die("[b]Could not get duplicates[/b]");
 
// Get the number of rows
$count=mysql_num_rows($result);
 
if($count == 1){
 
    /*
     *  Authenticated URL, validate user
     */
 
    // Prepare mysql statement
 
  $sql = "UPDATE userdata set validation='yes' WHERE email='$email'";
    mysql_query($sql) or die("Sorry, there was an error. Your account could not be validated");
 
    // Create cookies and store data
    setcookie( "oneword", $email, time()+3600, "/", "domain.com" );
 
    // Check if cookie is created successfully
    if (isset($_COOKIE["oneword"])){
        header("Location:http://www.domain.com/fun/index?ID=new_account");
        exit();
 
    }else{
        print "Your account has been activated. Please enable cookie in your browser to play ONEWORD.";
    }
}
 
?>
Here is the problem:
Every time I click on the mail, it gives me "Could not get duplicates" message. So, i guessed some how i am not able to get the values from the url. I did a "print" statement of the url and it prints correctly. Can some one please tell me where I am going wrong?

Do you think i need to clear blank spaces or purify the "email" and "code" before using it MySQL statement?

Any help will be appreciated.
Thank you
mischievous
Forum Commoner
Posts: 71
Joined: Sun Apr 19, 2009 8:59 pm

Re: Error in my activation.php script

Post by mischievous »

Check your variables....

$sql = "SELECT * FROM userdata WHERE email='$email' AND activationpassword='$code'";

// Execute statement
$result = mysql_query($mysql) or die("Could not get duplicates");



//SHOULD BE -->
$result = mysql_query($sql) or die("Could not get duplicates");
gimpact
Forum Commoner
Posts: 65
Joined: Tue Jun 16, 2009 11:08 pm

Re: Error in my activation.php script

Post by gimpact »

I am so silly. :crazy:

Thanks for the help
Post Reply