2011-08-03 43 views
1

所以連接已經建立,這裏是代碼。我試圖做的是從網址獲取兩個var並將它們保存爲var。我得到一個錯誤和PHP不工作,我知道URL中的信息是正確的,並與數據庫匹配。錯誤是「網址無效,或者您已經激活了您的帳戶。」這是什麼PHP返回,如果沒有一個匹配,所以即時通訊猜測斷開之間的url和var設置。 代碼:PHP-通過使用mysql進行url檢查var

if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['hash']) &&  !empty($_GET['hash'])){ 
// Verify data 
$email = mysql_escape_string($_GET['email']); // Set email variable 
$hash = mysql_escape_string($_GET['hash']); // Set hash variable 

$search = mysql_query("SELECT email, hash, active FROM users WHERE email='".$email."' AND hash='".$hash."' AND active='0'") or die(mysql_error()); 
$match = mysql_num_rows($search); 

if($match > 0){ 
    // We have a match, activate the account 
    mysql_query("UPDATE users SET active='1' WHERE email='".$email."' AND hash='".$hash."' AND active='0'") or die(mysql_error()); 
    echo '<div class="statusmsg">Your account has been activated, you can now login</div>'; 
}else{ 
    // No match -> invalid url or account has already been activated. 
    echo '<div class="statusmsg">The url is either invalid or you already have activated your account.</div>'; 
} 

}else{ 
// Invalid approach 
echo '<div class="statusmsg">Invalid approach, please use the link that has been send to your email.</div>'; 
} 
?> 

網址:

http://www.aliahealthcare.com/verify.php?email= '.ME @ email.com。' & hash ='。67f7fb873eaf29526a11a9b7ac33bfac'。

+0

什麼是不工作? – erisco

+0

你得到的錯誤是? – ain

+0

錯誤是「網址無效或您已經激活了您的帳戶。」這是什麼PHP返回,如果沒有一個匹配,所以即時通訊猜測斷開之間的url和var設置。 – Osman

回答

1

代碼看起來好像沒什麼問題

我會嘗試這樣做

$sql = "SELECT email, hash, active FROM users WHERE email='".$email."' AND hash='".$hash."' AND active='0'"; 

echo $sql; 

$search = mysql_query($sql); 

檢查所回顯的SQL看起來不錯,並嘗試在phpMyAdmin或通過CMDLINE運行它,以確認行確實存在這些參數