Re: Getting last record ID created from DB
| From: | Mark | Date: | Sat, 17 Mar 2007 13:38:07 +0000 |
| Subject: | Re: Getting last record ID created from DB | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250748@lists.php.net to get a copy of this message | ||
Rod Person wrote:
> On Fri, 16 Mar 2007 22:28:54 -0500
> "Jeff" <akaman@akaproz.com> wrote:
>
>> Is there a way to get the last Record # created by the DB.
>>
>
>>
>> $query = "INSERT INTO
t_users
>> (user_id, f_name,
>> l_name,
>> e_mail, b_date, NÌcÜ
>> I`lt�Q˜Äpic) VALUES ('', '$f_name', '$l_name',
>> '$e_mail', '$b_date', '')";
>> $result = mysql_query($query);
>> if(!$result)
>> {
>> die("Could not query the database: <br/>".mysql_error());
>> }
>> echo "Your Player information has been stored OK.<br />";
>>
>> what code could I add here to make the following line work?
>>
>> echo "REMEMBER your USER ID# you will need it when creating
>> Characters!! It is: $user_id"; <----- I want to
>> show the "user_id"
>> just created here.
>>
>> Thanks in advance!
>>
>
> select user_id from t_users where user_id = (select max(user_id) from
> t_users)
>
It should be noted that that is the absolute 100% WRONG way to do it. If
your site has any concurrency, you will almost certainly get the wrong
user.