为了账号安全,请及时绑定邮箱和手机立即绑定

mysqli最后插入ID

mysqli最后插入ID

郎朗坤 2019-10-22 21:36:08
我想将图像与名字,姓氏相关联...如何检索最后一行并将其插入到另一个表中?我试过$image = $mysqli->insert_id;然后绑定,但不起作用。有人可以帮我吗? $image = $mysqli->insert_id;//this should come from table2 $stmt = $mysqli->prepare("  insert into table1 (username, firstname, lastname, image)   select ?,?,?,image from table2 t2 where username = ? and  t2.id = ?    "); $stmt->bind_param('sssss', $username, $fname, $lname, $username, $image); $stmt->execute();
查看完整描述

3 回答

?
慕森王

TA贡献1777条经验 获得超3个赞

首先,您需要在ID中创建auto_increment字段


然后你可以用  $last_id = mysqli_insert_id($conn);


查看完整回答
反对 回复 2019-10-22
  • 3 回答
  • 0 关注
  • 857 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信