簡體   English   中英

mysql_insert_id()查看最后插入的記錄的值

[英]mysql_insert_id() to view value of last inserted records

我有一個將數據插入mysql數據庫的PHP腳本。 該表有一個自動遞增列。

我想使用mysql_insert_id()函數來獲取最后插入的記錄的值。

由於某種原因,這將返回值0,其中autoid列的值為300037。

任何幫助表示贊賞。 謝謝。

我的代碼段如下:

$sqlinsertdelivery="INSERT INTO deliverydetails (`LoadID1`,`deliveryroute`,`source`,`destination`,`route`,`CollectionArea1`, `CollectionArea2`, `CollectionArea3`, `CollectionArea4`, `CollectionDate`, `collectiontime`, `Destination1`, `Destination2`, `Destination3`, `Destination4`, `ArrivalDate`, `ArrivalTime`, `DeliveryCreationDateTime`, `DeliveryCreatedBy`,`comments`,`trailertype`) 
 VALUES
 ($loadnumber,'$route1','Hulamin','$dest1','$_SESSION[sessionrouteid]','$_POST[dispatchid1]','$_POST[dispatchid2]','$_POST[dispatchid3]','$_POST[dispatchid4]','$_POST[coldatetime]','$_POST[deltime]','$_POST[drop1]','$_POST[drop2]','$_POST[drop3]','$_POST[drop4]','$_POST[arrivedatetime]','$_POST[arrivetime]',CURRENT_TIMESTAMP,'$session->username','$_POST[comments]','$_POST[vehicletype]')
 ";
  if (!mysql_query($sqlinsertdelivery,$con))
   {
   die('Error with insert statement: ' . mysql_error());
   }


$delid = mysql_insert_id();
echo $delid;

遠射,但首先嘗試替換mysql_insert_id(); mysql_insert_id($con);

附帶一提,請告訴我這是將不在生產中的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM