PHP - Coupon (x) Uses
Ok, I laughed at how retarded I was trying to "experiment" on this code to be able to enter a coupon, how much receives, and how many uses before it expires. The main problem is when a member uses a coupon - I don't know how to remove a 'points' from mysql till it hits 0 then deactivates
coupons.php Code: [Select] <?php include('header.php'); foreach($_POST as $key => $value) { $protectie[$key] = filter($value); } if(isset($_POST['submit'])) { $ext1 = mysql_query("SELECT * FROM `coupons` WHERE `code`='{$protectie['code']}' AND `used`='0'"); $ext = mysql_fetch_object($ext1); if($ext->id != ""){ mysql_query("UPDATE `users` SET `coins`=`coins`+'{$ext->coins}' WHERE `id`='{$data->id}'"); mysql_query("UPDATE `coupons` SET `points`='-1' WHERE `code`='{$protectie['code']}'"); $mesaj = "<div class=\"msg\"><div class=\"msg success\">Success! You have received <b>{$ext->coins} coins</b>!</div></div>"; }else{ $mesaj = "<div class=\"msg\"><div class=\"error\">Error! This coupon code doesn't exist or is already used!</div></div>"; }}?> coupons-dashboard.php Code: [Select] <?php $del = $_GET['del']; $del1 = mysql_fetch_object(mysql_query("SELECT * FROM `coupons` WHERE `id`='{$del}'")); if($del1->id != ""){mysql_query("DELETE FROM `coupons` WHERE `id`='{$del}'");} $users = mysql_num_rows(mysql_query("SELECT * FROM `coupons`")); //if points go below 1, it deactivates $active = mysql_num_rows(mysql_query("SELECT * FROM `coupons` WHERE `points`='+0'")); $banned = mysql_num_rows(mysql_query("SELECT * FROM `coupons` WHERE `points`='0'")); ?> addcoupon-dashboard.php Code: [Select] <?php $n1 = rand(1000, 9999); $n2 = rand(1000, 9999); $n3 = rand(1000, 9999); $n4 = rand(1000, 9999); $code = $n1."-".$n2."-".$n3."-".$n4; if(isset($_POST['add'])){ mysql_query("INSERT INTO `coupons`(code, coins, points) values('{$_POST['code']}', '{$_POST['coins']}', '{$_POST['points']}')"); $message = "<div class=\"message success\"><h3>Success!</h3><p>Your coupon code is: ".$_POST['code']."</p></div>"; } $users = mysql_num_rows(mysql_query("SELECT * FROM `coupons`")); //$active = mysql_num_rows(mysql_query("SELECT * FROM `coupons` WHERE `used`='0'")); //$banned = mysql_num_rows(mysql_query("SELECT * FROM `coupons` WHERE `used`='1'")); //if points go below 1 - it becomes banned $active = mysql_num_rows(mysql_query("SELECT * FROM `coupons` WHERE `points`='+0'")); $banned = mysql_num_rows(mysql_query("SELECT * FROM `coupons` WHERE `points`='0'")); ?> also i have to say, SERIOUSLY the CAPTCHA? (john, george, paul, and.....??) im not a Beatles fan! haha Similar TutorialsHowdy everyone. I'm looking to find a developer to build a coupon / reward script that will allow businesses on my site to create coupons that their customers can be print / download. I was wondering if anyone out there has built a similar application before and has any advice before I take a stab at this. Any advice is appreciated, Thanks. Hi guys, I have a coupon software developed in PHP by some developers but I need to add a small functionality as the developers are not reachable anymore. The software is based on the LAMP model. I am NOT a PHP developer but can reasonably work with this stuff. First, let me give you a brief background of the system. The user gets the coupon from the website that the system auto generates and stores them in the user mgmt area which is coming from the mySQL database. Basically I need 3 things. 1. I need to have an encrypted URL (must be available from my system) that should carry both the code of the coupon (already system generated) and the Merchant ID (already in the system). 2. A small javascript or any other PHP code (to be placed in Merchant's sales page) that authenticates THIS URL which then calls an encrypted special page that holds the discounted page of the Merchant's product. 3. A small snippet of code to be kept in the 'Thank You' page of the Merchant's website which should then update the coupon status (redeemed/expired) back in my system. As far as variables of these coupons are concerned, I will manage that myself. But I just need the code or some good clear pointers to get this thing done. Please ask for any further clarification in case you don't understand what I described above. Any help would be greatly appreciated. Thanks in advance. Meenop Can anyone provide a snip of code that I could insert into the "coupon code" field on a formmail form which has the following effect: on submit form, user goes to the normal payment page (this is already implemented) if coupon code field is filled out with correct code, user is taken to alternate payment page on form submit. Either this or another approach which has the same result is OK. I am a novice coder working in a wysiwyg - I don't REALLY know php at all - I just need a snip I can insert and a clear instruction. Thanks so much for any help. |