Next primary key value

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

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 ).



php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

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

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 6 guests