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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.