Jump to content

coupon (x) uses


Vermino

Recommended Posts

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

<?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

<?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

<?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

Link to comment
https://forums.phpfreaks.com/topic/256442-coupon-x-uses/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.