On my free time I was bored and decided to make a promo item script. I
based it off the gpotato coupon page. It uses a 16 character code(4 characters per box). I used the cash shop login script so i didn't bother making a login script for it but if anyone would like me to leave a message here and I will make it when I have time.OK, here is the scripts for it.
Promo_Code.sql
used_promo.sql
promo.php
func.php
used_promo.sql
promo.php
PHP Code:
<?php
session_start();
?>
<!DOCTYPE HTML>
<header>
<title>Promotional Item</title>
<div align="center">
<?php
if (file_exists('func.php')) {
include 'func.php';
} else {
echo 'Sorry, was unable to locate the required script. =(';
exit();
}
if (!logged_in()) {
echo '<font color="red">You must be logged in to view this page!</font>';
exit();
}
?>
</div>
<script type="text/javascript">
function FocusMove(srcObj, maxLen, moveObj)
{
if (srcObj.value.length >= maxLen)
{
try
{
if(typeof(moveObj) != "object")
{
moveObj = document.getElementsByName(moveObj)[0];
}
moveObj.focus();
try{moveObj.select();}catch (E2){}
}
catch (E){}
}
}
</script>
</header>
<body>
<div align="center">
<form action="" method="post">
<p>Please insert your promotional item code below.</p> <br />
<input type="text" name="code1" maxlength="4" size="4 px" onkeyup="FocusMove(this,4,'code2');" autocomplete="off" /> -
<input type="text" name="code2" maxlength="4" size="4 px" onkeyup="FocusMove(this,4,'code3');" autocomplete="off" /> -
<input type="text" name="code3" maxlength="4" size="4 px" onkeyup="FocusMove(this,4,'code4');" autocomplete="off" /> -
<input type="text" name="code4" maxlength="4" size="4 px" autocomplete="off" /> <br />
<input type="submit" name="submit" value="Claim your promo item!" />
</form>
<footer>
<div align="center"><p>Made by <font color="blue">xXExiledXx</font></p></div>
</footer>
</div>
</body>
PHP Code:
<?php
function logged_in() {
return isset ($_SESSION['user_id']);
}
if (isset($_POST['submit'])) {
$code1 = $_POST['code1'];
$code2 = $_POST['code2'];
$code3 = $_POST['code3'];
$code4 = $_POST['code4'];
if (strlen($code1) > 4 || strlen($code2) > 4 || strlen($code3) > 4 || strlen($code4) >4) {
echo '<font color="red">Your promo code is too long please re-enter it!</font>';
exit();
} else{
mssql_connect('127.0.0.1', 'sa', '') or die(mssql_get_last_message());
$query = mssql_query("SELECT * FROM [Auth].[dbo].[Promo_Code] WHERE code1 = $code1 and code2 = $code2 and code3 = $code3 and code4 = $code4") or die(mssql_get_last_message());
$row_num = mssql_num_rows($query);
if ($row_num == 0) {
echo '<font color="red">You have put a invalid promo code!</font>';
exit();
} else {
$item = mssql_fetch_assoc($query);
$account_id = $_SESSION['user_id'];
$item_code = $item['item_code'];
$get_used_items = mssql_query("SELECT * FROM [Auth].[dbo].[used_promo] WHERE account_id = '$account_id' and item_code = '$item_code'");
$get_used_rows = mssql_num_rows ($get_used_items);
if ($get_used_rows > 0) {
echo '<font color="red">You have already used this promo code!</font>';
exit();
} else {
$account_id = $_SESSION['user_id'];
$item_count = $item['item_count'];
$rest_item_count = $item_count;
$format= "d/m/Y G:i:s";
$bought_time = date($format);
$valid_time = date("d/m/Y G:i:s", mktime(date("G"), date("i"), date("s"), date("m"), date("d")+30, date("Y")));
$taken_account_id = $account_id;
mssql_query("INSERT INTO [Telecaster].[dbo].[PaidItem](account_id,item_code,item_count,rest_item_count,bought_time,valid_time,taken_account_id) VALUES('$account_id','$item_code','$item_count','$rest_item_count','$bought_time','$valid_time','$taken_account_id')");
mssql_query("INSERT INTO [Auth].[dbo].[used_promo](account_id, item_code) VALUES ('$account_id', '$item_code')");
$get_nameid = mssql_query("SELECT * FROM [Arcadia].[dbo].[ItemResource] WHERE id='$item_code'");
$get_namecode = mssql_fetch_assoc($get_nameid);
$name_id = $get_namecode['name_id'];
$get_name = mssql_query("SELECT * FROM [Arcadia].[dbo].[StringResource] WHERE code = '$name_id'");
$name_sql = mssql_fetch_assoc($get_name);
$item_name = $name_sql['value'];
echo'Your <b>',$item_name,'(s)</b> has been place in ur item box. Have a great day!';
}
}
}
}
?>