more about Last_insert_id
| From: | Jacky@lilst | Date: | Thu, 25 Jan 2001 15:23:16 +0000 |
| Subject: | more about Last_insert_id | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-36543@lists.php.net to get a copy of this message | ||
I got here the syntax that is suppose to get the id from the "just inserted" record and
store it in value, did not work so far and I cannot see what is wrong in there, can anyone give me a
hint what is wrong here? ( And the reason I did not use mysql_insert_id here is because the ID field
at my tables are all BIGINT so mysql_insert_id won't work, so I have to use LAST_INSERT_ID()
instead). By the way, the error after the page is executed keep saying that "Mysql warning : 0
is not Mysql index" ( and point to the line "$FirstLast =
mysql_result($resultlast,0,0);"). And I did echo for teh value of $FirstLast, it showed that
there is no value in there.
Sniplet is like this:
$sql1 = "insert into firsttable (firstname, lastname)
values('Jack','Chan')";
$resultsql1 = mysql_query($sql1);
$sqlLastID = "select LAST_INSERT_ID() from firsttable";
$resultlast = mysql_query($sqlLastID);
$FirstLast = mysql_result($resultlast,0,0);
$sql2 = "insert into secondtable (FirsttableID,secfirstname, seclastname)
values('$FirstLast','Jacky','Chany')";
$resultsql2 = mysql_query($sql2);
$sqlLastIDsec = "select LAST_INSERT_ID() from secondtable";
$resultlast2 = mysql_query($sqlLastIDsec);
$secondLast = mysql_result($resultlast2,0,0);
$sql3 = "insert into Thirdtable (SecondTableID,FirsttableID,Thirdfirstname, Thirdlastname)
values('$secondLast','$FirstLast','Steve','Chan')";
$resultsql3 = mysql_query($sql3);
$sqlLastIDthird = "select LAST_INSERT_ID() from Thirdtable";
$resultlast3 = mysql_query($sqlLastIDthird);
$ThirdLast = mysql_result($resultlast3,0,0);
******************
what have I done wrong? Please enlighten me here
Thanks
Jack
jacky@activelifestyle.com
"There is nothing more rewarding than reaching the goal you set for yourself"