我希望将图像与名字和姓氏相关联... 我如何检索最后一行并使用它插入到另一个表中? 我尝试了$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();
insert_id;
,例如:if ($stmt->execute()) $image = $stmt->insert_id;
。这将返回插入行的ID,并将其分配给$image
变量。请注意不要改变原始意思。 - Iłya Bursovt2.id = ?
? - user2926655