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.
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.
Set voucher field AUTO_INCREMENT in MySQL table with zero fill. This way you will get unique ids everytime as Phase told.
i agree with mwasif. make it BIG INT, 8 character range, auto_increment, zero fill, and primary key. that should do.
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