我有两张桌子:
发票&发票零件
我使用两个表的原因是因为我不想将发票部件数组保存到发票表中的一个记录中,我不想将其保存到发票表中的多个记录中。
当我将数据提交到两个表格时,如果我还没有ID,如何将这两个表格与ID链接?
$result = mysqli_query($mysqli, "INSERT INTO invoices(labelwarning, status, todaysdate, todaystime, todaysdatetime, avatar, firstname, lastname, mwaid, nextgenid, manager, manageremail, dispatcher, dispatcheremail, techemail, tag, serialnumber, currentequipment, company, address, city, state, zip, contactperson, contactnumber , currentdate, timearrived, timecompleted, login_id) VALUES('$labelwarning', '$status', '$todaysdate', '$todaystime', '$todaysdatetime', '$avatar', '$firstname', '$lastname', '$mwaid', '$nextgenid', '$manager', '$manageremail', '$dispatcher', '$dispatcheremail', '$techemail', '$tag', '$serialnumber', '$currentequipment', '$company', '$address', '$city', '$state', '$zip', '$contactperson', '$contactnumber ', '$currentdate', '$timearrived', '$loginId')");
$result2 = mysqli_query($mysqli, "INSERT INTO invoiceparts(partnumber, partdescription, partprice, partquantity, partdb, login_id) VALUES '$partnumberstring', '$partdescriptionstring', '$partpricestring', '$partquantitystring', '$partdbstring', '$loginId')");
答案 0 :(得分:1)
如果您需要链接" login_id"并且使用AUTO_INCREMENT生成login_id,然后您可以通过
来完成如果login_id不是AUTO_INCREMENT字段,那么您可以按
进行操作它将从那里返回最后一个插入的行,我们可以获取login_id