[Release] Promo item script

02/07/2012 23:15 XavierDeFawks#1
Hello,
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
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>
func.php
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) > || strlen($code2) > || strlen($code3) > || 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!';
            }
        }
    }
}


?>
02/10/2012 06:18 akindain#2
hmm will give this a try and let ya know thanks for sharing
02/10/2012 15:26 ismokedrow#3
Eww it uses the MSSQL api. No worries mate. I will write out the MSSQL and pm you a SQLSRV copy so you can update this post. I am pretty sure Microsoft officially depreciated the MSSQL Api in favor of the SQL Driver. :D PM you soon.
02/10/2012 22:26 XavierDeFawks#4
Ok, Thank you drow! :D
03/31/2013 17:13 orionware#5
Ok, Thank you

Is that it would be possible to have the php authentication for your promo item which is really great!

Sorry for bad english i am french
07/10/2013 20:09 BartSimpson99#6
for what is this script?
07/10/2013 21:01 gr4ph0s#7
Quote:
Originally Posted by BartSimpson99 View Post
for what is this script?
For php.

Noob question ! Noob answer

Hope you like me :troolll: