【问题标题】:Can't output md5 hash as the same one in the database无法在数据库中输出相同的 md5 哈希
【发布时间】:2015-01-27 10:52:40
【问题描述】:

我有个小问题希望你能解决。

每当我尝试从数据库中检索哈希时都会收到此错误: 'where 子句'中的未知列'26657d5ff9020d2abefe558796b99584'

这是我的 php 代码:

<?php

if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['hash']) && !empty($_GET['hash'])){

//Verifier les données

    $email = mysql_real_escape_string($_GET['email']);
    $hash = mysql_real_escape_string($_GET['hash']);

    $verification = mysql_query("SELECT email, hash, status FROM utilisateurs WHERE Email = '".$email."' AND
    $hash = '".$hash."' AND status = '0'") or die(mysql_error());
    $match = mysql_num_rows($verification);

    echo $match; // Just for testing how many matches we'll get. We expect "1" or "0"

}else{ 

    //Invalid approach

    echo "Invalid approach, please use the link that has been send to your email.";

}


?>

所以当我测试 url 时:http://mywebsite.com/verify.php?email=name@gmail.com&hash=26657d5ff9020d2abefe558796b99584 我确定哈希值存在,因为我使用相同的电子邮件从数据库中复制了它

我得到错误: 'where 子句'中的未知列'26657d5ff9020d2abefe558796b99584'

哈希是这样生成的:$hash = md5(rand(0,1000));

任何帮助将不胜感激!

【问题讨论】:

    标签: php mysql hash md5


    【解决方案1】:

    您的 SQL 查询包含以下子句:

    … AND $hash = '".$hash."' AND …
          ^^^^^
    

    您要检查hash 列的值,而不是$hash

    【讨论】:

    • 天哪,非常感谢你,有时你只关注不存在的硬东西,而不是只看最简单的东西。再来一次谢谢!
    猜你喜欢
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多