Any expert please help?

Discussion in 'Programming' started by sue89, May 23, 2008.

  1. #1
    Hi there,

    I am currently doing a vouchers page using PHP.
    But I am having problem with the serial numbers.
    I will need roughly 8 numbers on the voucher page.

    All I know by using PHP is to type this.

    <?php
    $randnum = mt_rand(10000000,99999999);
    echo "$randnum";
    ?>

    However, how do I make sure that after
    1) generating this numbers it will become unique and not generate again.
    2) how do I go about inserting into database? what are the codes to insert and pull out again?
    3) do I have to encrypt the serial numbers inside database or just insert in?

    If anyone could help, really thanks a lot.
     
    sue89, May 23, 2008 IP
  2. Phase

    Phase Active Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    93
    #2
    Use MySQL.

    Look on http://php.net for the mysql functions.

    As for the unique numbers, don't use a random number generator, use a number thats increased each time something is successfully instered into the database. For example: You might have one of the tables in a row of information called ID, and each time PHP inserts data into that table, it reads the last ID, and adds one to it, then inserts the new number into the new row.

    You don't HAVE to encrypt them, no. If you plan on storing data like addresses, and phone numbers then you should encode them in some form or fashion before they are inserted into the database for *some* security (even though it's very little) -- It just ensures that if someone gets a hold of just the database, and not the location of the password then they can't read it.
     
    Phase, May 24, 2008 IP
  3. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #3
    Set voucher field AUTO_INCREMENT in MySQL table with zero fill. This way you will get unique ids everytime as Phase told.
     
    mwasif, May 24, 2008 IP
  4. bluecape

    bluecape Peon

    Messages:
    89
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i agree with mwasif.
    make it BIG INT, 8 character range, auto_increment, zero fill, and primary key. that should do.
     
    bluecape, May 25, 2008 IP
  5. sue89

    sue89 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi, you guys means I have to have a voucher id in a row and serial_id in a seperate row?

    Bluecape you sai that make it BIG INT, 8 character range? You mean for the serial_id or?

    My next issue will be to store the expiry_date which is one year later. 365days but when i just type:

    $expiry_date = the date now +365 right it wouldn't work.
    And can i know what's the data type when you insert into database?

    Thanks for those who helped :)
     
    sue89, May 26, 2008 IP