Verifying Redemption Code

[insert_php]
//………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………

$servername = “10.210.225.114”;
$username = “newadmin”;
$password = “Mrz7dlzrndwifQl”;
$dbname = “newdb”;
$code = ‘\’R7o8xskl\”;
//$sql = “”;
$rid = $_POST[‘RLLPlanId’];
$result = “”;

echo $code;
echo “
“;
echo “‘”.$code.”‘”;

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
$conn1 = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
echo “Connection failed: ” . $conn->connect_error;
}

else{

if($_POST[‘GrouponPlanId’]){ // Handle Groupon redemption codes
$sql = “SELECT * FROM GrouponPlanCodes WHERE GrouponPlanId = “.$_POST[‘GrouponPlanId’].” and Code ='”.$_POST[‘code’].”‘” .” and IsUsed = 0″ ;
$result = mysql_query($sql);

if ((int)mysql_num_rows($result) == 0 )
{
if($_POST[‘GrouponPlanId’] == 1){
$sqlUpdate = “UPDATE GrouponPlanCodes SET IsUsed=1 WHERE GrouponPlanId = “.$_POST[‘GrouponPlanId’].” and Code ='”.$_POST[‘code’].”‘” .” and IsUsed = 0″;

if ($conn1->query($sqlUpdate) === TRUE) {
$conn1->close(); $conn->close();
echo ‘‘;
}
else {
$conn1->close(); $conn->close();
echo ‘‘;
}
}
}
}

else{ // Handle RLL Plan redemption codes

$sql = “SELECT * FROM RLLPlanCodes WHERE RLLPlanId = “.$rid.” and Code =”.$code.” and IsUsed = 0″ ;

$result = mysql_query($sql);

//check if no record return
if ((int)mysql_num_rows($result) == 0 )
{
if($_POST[‘RLLPlanId’] == 1){
$sqlUpdate = “UPDATE RLLPlanCodes SET IsUsed=1 WHERE RLLPlanId = “.$_POST[‘RLLPlanId’].” and Code ='”.$_POST[‘code’].”‘” .” and IsUsed = 0″;

if ($conn1->query($sqlUpdate) === TRUE) {
$conn1->close(); $conn->close();
echo ‘‘;
}
else {
$conn1->close(); $conn->close();
echo ‘‘;
}
}
else if($_POST[‘RLLPlanId’] == 2){
$sqlUpdate = “UPDATE RLLPlanCodes SET IsUsed=1 WHERE RLLPlanId = “.$_POST[‘RLLPlanId’].” and Code ='”.$_POST[‘code’].”‘” .” and IsUsed = 0″;

if ($conn1->query($sqlUpdate) === TRUE) {
$conn1->close(); $conn->close();
echo ‘‘;
}
else {
$conn1->close(); $conn->close();
echo ‘‘;
}
}
else if($_POST[‘RLLPlanId’] == 3){
$sqlUpdate = “UPDATE RLLPlanCodes SET IsUsed=1 WHERE RLLPlanId = “.$_POST[‘RLLPlanId’].” and Code ='”.$_POST[‘code’].”‘” .” and IsUsed = 0″;

if ($conn1->query($sqlUpdate) === TRUE) {
$conn1->close(); $conn->close();
echo $conn1->query($sqlUpdate);
echo ‘‘;
}
else {
$conn1->close(); $conn->close();
echo ‘‘;
}
}
}
else
{
$conn1->close(); $conn->close();
echo ‘‘;
}
}

}

[/insert_php]