I have some code that generates random numbers like some discount coupon codes. Each time a list of new codes is prepared and I want to save it to the database, the new list is prepared every time and so I want to save it to the database.
& lt;? Php $ db = new mysqli ('localhost', 'root', '', 'store'); If (mysqli_connect_errno ()) {echo 'could not connect to the database: plz try sometime time ..'; Go out; } $ Coupon = 8; Number of coupons $ size = 10; ($ I = 0; $ i & lt; $ coupon; $ i ++) // number of the characters {$ code = copy stripupper (substrate (MD5 (time (.) Rand (100009999) ), 0, $ size); echo "<$"> $ Qry = "Enter code (code) values ('$ coupon')"; $ result = $ db-> query ($ Qry);}
I assume that this code does not run for you Trying below - I've made some changes:
$ coupon = 8; Number of coupons $ size = 10; ($ I = 0; $ i & lt; No. of characters for $ coupon; $ i ++) Well, // is not a very good random generator (at that time) ... $ code = strtoupper (substr (md5 (time () .rand (1000099999)), 0, $ size); $ qry = "Enter code (code) values ('$ code')"; $ result = $ db-> query ($ qry);}
No comments:
Post a Comment