Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Next primary key value

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Next primary key value

Postby legendin » Fri Apr 26, 2013 2:09 am

Hi everyone,

I'm new to php and mysql and need some advices.

Is there a method to retrieve the primary key for the next database entry? I have defined some tables in mysql and would like to insert entries to the tables through php code,however, what is the best way to retrieve the next primary key( Max+1 ).


New php-forum User
New php-forum User
Posts: 2
Joined: Fri Apr 26, 2013 1:58 am

Re: Next primary key value

Postby seandisanti » Fri Apr 26, 2013 8:17 am

When you setup your table, set your primary key field to auto increment. Then when you insert, don't include that field in the fields to be inserted, and it will automatically be given the next available id
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.