mysql データベースにデータを挿入する PHP スクリプトがあります。テーブルには自動インクリメント列があります。
mysql_insert_id() 関数を使用して、最後に挿入されたレコードの値を取得したいと考えています。
何らかの理由で、autoid 列の値が 300037 の場合に値 0 が返されます。
任意の支援をいただければ幸いです。ありがとうございました。
私のコードスニペットは以下の通りです:
$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;