Re: Urgent help needed, sound scary when anyone did that on title :-)
| From: | Joe Stump | Date: | Thu, 25 Jan 2001 03:25:42 +0000 |
| Subject: | Re: Urgent help needed, sound scary when anyone did that on title :-) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-36546@lists.php.net to get a copy of this message | ||
remove the result - so just type $id = mysql_insert_id() and it should work
fine.
--Joe
On Thu, Jan 25, 2001 at 10:21:17AM -0600, Jacky@lilst wrote:
> Hi people,
> 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 the value of $FirstLast, it showed that
> there is no value in there.
>
> Sniplet is like this: ( I tried to keep this down as much as try to give most detail at the
> same time, so apologize for too long sniplet).
>
> $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"
--
Joe Stump, PHP Hacker
joestump98@yahoo.com
http://www.miester.org/