Web Design, Development & Marketing
acuras services: Website Design & Development E-commerce Solutions Content Management Systems Online Marketing & Social Media Corporate Branding Social Media Training
Get in touch... Email Us: info@acuras.co.uk
acuras blog:7 Quick Tips to Keep Your SEO On Track in 2012 7 Social Media & SEO Tactics Businesses Will Adopt in 2012 latest posts:We are now trading as a Limited company Recent Work: Digital Marketing Material and Website Re-Designs Affordable Web Hosting and Domain Name Registration New Acuras Logo Coming Soon... Barclaycard ePDQ CPI Integrations HSBC XML API / CPI E-commerce Integrations Photoshop to Valid XHTML/CSS Coding Service Recommended Open Source Invoicing System Reasons Businesses should Embrace the Web blog archive:
Web Development ArticlesPHP: Use mysql_insert_id() To Get The Last Entered Auto Increment Value
Published: 6th Apr 2006
The mysql_insert_id() function is a very handy PHP function that enables you to get the auto incremented value that was created from the last MySQL query executed. See the following PHP:
For this example, the "items" table has a field "item_id" which is set to auto increment when a new record is entered. You do not need to put "item_id" in the list of fields in the MySQL query although some would prefer to include it in the query (you would insert a NULL for its value). After executing the MySQL query, you can pass mysql_insert_id() to a variable of your choice and then use this value for whatever you need it for. In some cases, you may be using this ID as a foreign key in another table so you would use $lastItemID, as seen in the example above, within another MySQL INSERT command for a different table. Related LinksRelated Articles / PostsBarclaycard ePDQ CPI Integrations (27/05/2009) HSBC XML API / CPI E-commerce Integrations (02/04/2009) Recommended Open Source Invoicing System (25/03/2009) Recent Recommended Links - October 2008 (03/10/2008) Controlling PHP Register Globals Using .htaccess File (04/03/2008) |
||