Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,233
    Thanks
    51
    Thanked 100 Times in 99 Posts

    Adding a unique record to DB

    I want to create a contest page, and the contest ID I want to be unique, it'd mess things up if two contests were the same number.

    Using RAND won't work. How can I insert a record that is unique into mysql?

  • #2
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Set it to auto_int as that way it will make the number itself like a primary ID number once auto_int is active on a table column and a row is added it will auto put the number in.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,233
    Thanks
    51
    Thanked 100 Times in 99 Posts
    Do I have to make it a primary key? and also do I insert any value for it, or will it auto insert a number?

  • #4
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    If its auto_int the mysql query for inserting a new row will insert the id number for you so you wont need to worry about the ID and yes you will need to make it a Primary Key.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •