Re: PHP & MySQL get value of auto_increment field of new data
| From: | Vijest.com | Date: | Thu, 09 Nov 2000 10:43:07 +0000 |
| Subject: | Re: PHP & MySQL get value of auto_increment field of new data | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24474@lists.php.net to get a copy of this message | ||
You can use SELECT count(*).
At webpage in PHP code you can use mysql_numrows query, or last_insert_id, or SELECT id from
tablename desc limit 1;
If two people enter the data at the same time, one of this queires will communicate with database
before second request.
So, you have no problem at all.
lancelot_
At 13:06 2000.11.08 -0500, Tom Harris wrote:
>Hi folks,
>
>The dumb newbie has a question...
>
>I use a PHP script to take data from a web form and insert it into a MySQL
>database. The database has an id field that is AUTO_INCREMENTing and the
>primary key. I want to be able to retrieve the id field that belongs to the
>record I just inserted.
>
>My first thought was to just pull out the highest value in the id field, but
>what happens if two people are entering data at the same time? I'm sure
>this is unlikely, but I would think there would be another way.
>
>I also thought about sending a query to match the data just entered, but the
>only field that would be unique would be a giant text field that is probably
>not a good idea to perform searches on.
>
>Any suggestions?
>
>Thanks,
>
>-T
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net