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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!