Code Verification

$servername = “10.210.225.114”;
$username = “newadmin”;
$password = “Mrz7dlzrndwifQl”;
$dbname = “newdb”;
// 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;
}

$stmt = $conn->
prepare(“SELECT * FROM wp_codes where code=?”);
$stmt->bind_param(i, $code_input);
$code_input = $_POST[‘code’];
$stmt->bind_result($code, $is_used, $email);
$stmt->execute();

$found = FALSE;

while ($row = $stmt->fetch()) {
$found = TRUE;
if($is_used == 1)
{
$conn1->close();
$conn->close();
echo “This code has already been activated. Please use a different code or contact customer service support@thefresh20.zendesk.com”;

}
else
{
$stmt1 = $conn1->prepare(“update wp_codes set is_used=1 where code=?”);
$stmt1->bind_param(i, $code_input1);
$code_input1 = $_POST[‘code’];
$stmt1->execute();
$conn1->close();
$conn->close();
echo ““;
}

}

if($found == FALSE)
{
$conn1->close();
$conn->close();
echo “The code is not valid, check your entry and try again.”;

}

?>