這裏我試圖從我有product_id的表中的MySQL數據庫中獲取插入的標識。插入後,我想獲得最新插入的product_id並將其存儲在數組中['newid'][]
如何獲取PHP中的最後一個插入的標識
插入查詢進行得相當不錯,但我無法將product_id存入數組。當我打印數組時,我得到的值爲NULL
。
$link = mysqli_connect(db_host,db_user,db_password,db_name);
if (condition) {
$sqlin = "INSERT INTO product_list (product_name, product_category, product_price,product_description,product_sharing_basis,product_co_owners,walden_product_price,product_referrence_URL,product_proposed_user_id,product_image_url,product_refurbish_factor,product_insurance_factor,product_life,product_size_category,product_publish_status) VALUES ('$product_name', '$product_category', '$product_price', '$product_description', '$share_basis', '$co_owners', '$walden_product_price', '$pro_url', '$proposed_by','files/uploaded_images/".$_FILES['file']['name']."', '$refurbishment_factor', '$insurance_factor', '$product_life', '$size_category','$approve')";
} else {
$sqlin = "INSERT INTO product_list (product_name, product_category, product_price,product_description,product_sharing_basis,product_co_owners,walden_product_price,product_referrence_URL,product_proposed_user_id,product_image_url,product_refurbish_factor,product_insurance_factor,product_life,product_size_category) VALUES ('$product_name', '$product_category', '$product_price', '$product_description', '$share_basis', '$co_owners', '$walden_product_price', '$pro_url', '$proposed_by','files/uploaded_images/".$_FILES['file']['name']."', '$refurbishment_factor', '$insurance_factor', '$product_life', '$size_category')";
}
if(mysqli_query($link, $sqlin)){
$newisid = mysqli_insert_id($link);
$_SESSION['newid'][] = $newisid;
我該如何解決這個問題?
你如何打印您陣列,並有啓動會議在你的網頁上? – Saty
'「插入查詢進行得非常好」......但是你的英語語法卻很差勁。你的意思是說''進行得很好'。' –
@Saty是的,我已經開始會話。我使用echo var_dump($ _ SESSION ['newid']);打印。 –