我正在尝试验证从以下电子邮件ID发送的电子邮件,它已发送到具有激活链接的特定电子邮件但无法激活。这是用于数据库连接的两个页面database_connection.php和用于激活的active.php。 \
database_connection.php
/*Define constant to connect to database */
DEFINE('DATABASE_USER', 'db_user');
DEFINE('DATABASE_PASSWORD', 'db_password');
DEFINE('DATABASE_HOST', 'localhost');
DEFINE('DATABASE_NAME', 'trqnwr_forum');
/*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', 'ismaakeel@gmail.com');
DEFINE('WEBSITE_URL', 'http://www.leedsit.com/reg');
// 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());
}
?>
active.php
<html>
<body><?php
include ('database_connection.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 class="success">Your account is now active. You may now <a href="login.php">Log in</a></div>';
} else
{
echo '<div class="errormsgbox">Oops !Your account could not be activated. Please recheck the link or contact the system administrator.</div>';
}
mysqli_close($dbc);
} else {
echo '<div class="errormsgbox">Error Occured .</div>';
}
?>
</body>
</html>
答案 0 :(得分:0)
使用此代码
if (mysqli_affected_rows($result_activate_account) == 1)
而不是
if (mysqli_affected_rows($dbc) == 1)
问题是您没有将结果作为资源传递。