如何在我的数据库中插入最后一个ID
这是我的代码:
$id = $_POST['c_id'];
$var_id = $_POST['var_id'];
$var_name = $_POST['variable_name'];
$saveVar = "INSERT INTO ".$table_sub_var."
VALUES(NULL,".$var_id.",".$var_name.")";
mysqli_query($connect,$saveVar);
答案 0 :(得分:0)
您可以使用mysqli_insert_id()
方法:
$id = $_POST['c_id'];
$var_id = $_POST['var_id'];
$var_name = $_POST['variable_name'];
$saveVar = "INSERT INTO ".$table_sub_var."
VALUES(NULL,".$var_id.",".$var_name.")";
mysqli_query($connect,$saveVar);
$last_inserted_id = mysqli_insert_id($connect); // return last inserted ID