我想抓插入数据库最后一笔数据的ID(为主键递增),把这个ID变量传递到下一页面,方便获取使用,使用了$select="select last_insert_id() ";来获取,此方法初次使用,导致不是报错就是抓空值,有请个位大虾,伸出援助之手代码片段:<?php@ $db=new mysqli('localhost', 'bm_user', 'password', 'ivortt');if (mysqli_connect_errno()){echo "Connect Error: Could not connect to database. Please try again later.<br />";exit;}//insert values into table joblist$query_info="insert into hr_jl(id,timecoll,college1,school_type,college,craft,degree,english,compute,interest,time_one,time_two,item_name,practice_responsibility0,description_practice0) values('".$id."','".$timecoll."','".$college1."','".$school_type."','".$college."','".$craft."','".$degree."','".$english."','".$compute."','".$interest."','".$time_one."','".$time_two."','".$item_name."','".$practice_responsibility0."','".$description_practice0."')";$result=$db->query($query_info);if($result) {echo include("student_baseinfo.php?id=$id"); }else {echo "Insert Error:An error has occurred. The item was not added.<br />";}$db->close();?>我该怎么使用last_insert_id()获得ID是值?补充一下: 字段:ID类型:BIGINTAUTO_INCREMENT
2 回答
Smart猫小萌
TA贡献1911条经验 获得超7个赞
if($result) {
// 加这一句
$id = $db->insert_id;
echo include("student_baseinfo.php?id=$id");
}else {
echo "Insert Error:An error has occurred. The item was not added.<br />";
}
再有在插入的时候,你那id值不用管嘛,插完了你只要$db->insert_id一下就知道插入的那条记录的ID是多少了,你干嘛费力巴撒的在没插之前就去确定当前要插的记录的ID呢,ID本来就是自增的,不用管他的嘛
- 2 回答
- 0 关注
- 123 浏览
添加回答
举报
0/150
提交
取消