PHP-获取var从url检查与mysql


PHP- Getting var from url checking with mysql

所以连接已经建立,下面是代码。我想做的是从url中获得两个var并将它们保存为var。我得到一个错误,php不工作,我知道url中的信息是正确的,与数据库匹配。错误是"url是无效的或者你已经激活了你的帐户。"这是什么php返回,如果没有匹配,所以我猜断开是在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>';  
}  
?>
URL:

http://www.aliahealthcare.com/verify.php?email= .me.com。和散列= .67f7fb873eaf29526a11a9b7ac33bfac。

看起来PHP是坚实的,所以我不认为这是你的问题。我不禁注意到,虽然你在URL中有几个'.'。我认为你需要摆脱他们:

http://www.aliahealthcare.com/verify.php?email=me.com&散列= 67 f7fb873eaf29526a11a9b7ac33bfac

在使用mysql_real_escape_string之前,请尝试回显电子邮件和散列值。我敢打赌代码没问题,但我怀疑输入。

代码看起来很好

我会尝试做这个

$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运行它,以确认这些参数

是否存在一行。