How to post id with auto increment and without duplication
NickName:user3809295 Ask DateTime:2015-12-08T18:02:24

How to post id with auto increment and without duplication

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++;
        ?>

Copyright Notice:Content Author:「user3809295」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34152985/how-to-post-id-with-auto-increment-and-without-duplication

Answers
jay 2015-12-08T10:09:34

you dont need to set id in insert query you can do that\n\n$query=\"INSERT INTO table (name) VALUES('$name')\";\n\n\nand set id column as Primary and auto-increment in database",


More about “How to post id with auto increment and without duplication” related questions

How to post id with auto increment and without duplication

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

Show Detail

avoid duplication with auto increment key in Hibernate

I am trying to use Hibernate to auto increment the id, however, I try to avoid duplication. class Service { Long id; // auto increment String name; String owner; Boolean increment...

Show Detail

WP Post ID Auto Increment

I was trying something and edited one of the post IDs from 100 to 10000. I switched it back to 100 after the test. Now, every time I add posts, pages, images, etc, the ID would now auto increment

Show Detail

Auto Increment a row (ID)

I'm trying to AUTO_INCREMENT a row. When creating a row for the table, is INT better than TEXT? I use varchar for the other rows, but I presume using AUTO_INCREMENT with varchar would be completely

Show Detail

Change auto increment id to last without Django ORM

I want to refresh auto increment 'order_id' from between rows to next of last row in database layer without Django ORM. my 'order_id' field is integer and it's auto increment in MySQL for example I...

Show Detail

Exxclude ID (auto increment) from POST request in rest-layer

I am using https://github.com/rs/rest-layer for creating my CRUDL APIs. In my postgres database I have a ID field (integer, auto increment). In my schema I have ID defined like this: ...

Show Detail

Atomic increment of a non auto_increment column in MySQL

I have a table with two columns. One is auto_increment say columnA whereas other is a non auto_increment say columnB. I want to perform two types of insert operations in columnB: Insert a constant

Show Detail

auto increment id practice

I wanted to know if adding an auto-increment primary index to each table (along or without any other relationship between keys of other table) a good practice? Example: whenever I create any tabl...

Show Detail

How to get auto_increment id without insert in SQL Server Management Studio?

As I know the command to find the AUTO_INCREMENT Value in SQL Server: SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DatabaseName AND TABLE_NAME = TableName; But if I

Show Detail

Loopback4 MySQL Auto-Increment ID

I've just installed Loopback4 (based on TS) and i'm trying to play around with it since it seems really easy to create an API using it. My question is rather simple (yet i dont know the answer). Ho...

Show Detail