du8864 2016-10-11 23:10
浏览 231
已采纳

从sql保存并获取哈希值

first I create a hash code and save it in my database:

$key = md5(uniqid(rand(), true));
$update = mysqli_query($conn, "UPDATE my_table SET md5key = MD5('$key') WHERE id = 1");

But the $key does not match the code in the database?

$key = e114e5bd4c8551d4e46a636d0c087b0e database = c00855d30f0c2c2f527b95f8be86a8b3

My field in the database has the following option:

md5key varchar(255) utf8_general_ci

Whats wrong here?

</div>
  • 写回答

1条回答 默认 最新

  • duan97689 2016-10-11 23:16
    关注

    I think that's because your $key variable has an MD5 hash already, but when you make the update query, you use a MD5 function again, so the value inserted in the database will be different.

    Just do this:

    $key = md5(uniqid(rand(), true));
    $update = mysqli_query($conn, "UPDATE my_table SET md5key = '$key' WHERE id = 1");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记