-4

I want to add some random number that created by PHP to my SQL without repeat. I use this code to create 14 length random:

for ($i=0;$i<10;$i++) {
        $n1 = rand(100000,999999);
        $n2 = rand(100000,999999);

        $pincode = (string)$n1.(string)$n2;
    echo $pincode;
    echo nl2br("$pincode\n");

Now I want to input created a number in My SQL and ignore the repeated number. How can I do that ?

sohrab
  • 43
  • 1
  • 4
  • 4
    Stop posting the same question http://stackoverflow.com/q/17716441/1920232. Edit your original one. – peterm Jul 18 '13 at 07:45

2 Answers2

0

The best way is to use timestamp. It shall always be unique and no chance of duplicacy.

Afroz Alam
  • 854
  • 6
  • 17
0

Afroz, timestamp is probably unique, but very predicteable ;-)

This might be interesting: How to 'insert if not exists' in MySQL?

Community
  • 1
  • 1
MBaas
  • 5,834
  • 4
  • 36
  • 53