如何使用自动增量发布id而不重复

How can i post integer id in database manually without a duplication.I tried many codes but not working.

Below is my code how can i check if id is empty and Post id without duplicating

        <input type="hidden" name="id" value="1"/>
        <?php
        $id = $_POST['id'];
        $query = mysql_query("SELECT * FROM table") or die(mysql_error());
        while ($row = mysql_fetch_assoc($query)){
        $id = $row['id'];
        $i=1;
        if($row['id']!=$id){
        $i=1;
        }
        $id = $row['id'];
        $query="INSERT INTO table (id,name,) VALUES('$id','$name')";
        i++;
        ?>

you dont need to set id in insert query you can do that

$query="INSERT INTO table (name) VALUES('$name')";

and set id column as Primary and auto-increment in database

Always use table creation like that

CREATE TABLE table_name
(
ID Integer PRIMARY KEY AUTOINCREMENT,
Name varchar(255) NOT NULL
)

run this sql query on phpmyadmin or mysql terminal . it will create the table with two column name ID and Name and column ID with primary key and auto increment. whenevery you insert the new record you don't need to check duplicate value new record will store with NEW ID .