Reputation: 73
I am trying to validate a mail account by sending a activation link to the given mail id. For that i am generating a random number and storing it as check_activation in database. No the problem is, no matter what id i pass in the link, the database gets updated.
Part of my codes are;
validation page:
$username = $_SESSION['username'];
include "connect.php";
$query = "select * from data_main where username = \"$username\"";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
$id_string = $row['check_activation'];
$query = "update data_main set check_activation = 'validated' where check_activation = \"$id_string\" ";
$retrn = mysql_query($query) or die(mysql_error());
if($retrn !== true)
{
echo "error in validation".mysql_error();
exit;
}
this is the activation link i am sending to the user.
$mail_body.="http://$servr/dir_name/checkactivation.php?check_activation=$textstr";
is there any other method i can use to validate a email account. the account should be activated only after the user click the given link and validate it.
Upvotes: 2
Views: 145
Reputation: 6565
try this
include "connect.php";
$username = $_SESSION['username'];
$id_string = $_GET['check_activation'];
$query = "select * from data_main where username = '{$username}' AND check_activation = '{$id_string}'";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
$retrn = false;
if($rows == 1)
{
$query = "update data_main set check_activation = 'validated' where check_activation = '{$id_string}' ";
$retrn = mysql_query($query) or die(mysql_error());
}
else
{
echo "error in validation".mysql_error();
exit;
}
You should use MySQLi or PDO to do you DBConnection
Upvotes: 1