du_1993
2016-04-09 19:30 阅读 51
已采纳

mysqli_insert_id()总是返回NULL

mysqli_insert_id() always returning null.I cannot understand the reason for this

    $blocksql="insert into blockinfo values(NULL,'$user','$book','$blocktime','$quant1','$flag','$title')";

    mysqli_query($con,$blocksql);
    $id=mysqli_insert_id();
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dqv2743 dqv2743 2016-04-09 19:34

    You're not passing a connection to mysqli_insert_id() of course it will always be null.

    $id = mysqli_insert_id($con);
    
    点赞 评论 复制链接分享
  • dongyanzhui0524 dongyanzhui0524 2017-04-27 16:31

    mysqli_insert_id() always returning null cause you don't pass mysqli database connection variable parameter .

    $con = mysqli_connect("Host","UserName","Password","DatabaseName");
    $blocksql="insert into blockinfo values(NULL,'$user','$book','$blocktime','$quant1','$flag','$title')";
    
    mysqli_query($con,$blocksql);
    $id=mysqli_insert_id($con);
    

    I hope this will work for you.Otherwise you can see php manual.

    http://php.net/manual/en/mysqli.insert-id.php

    点赞 评论 复制链接分享

相关推荐