-
-
Save adrianrodriguez/48cd90067a63691adc6a to your computer and use it in GitHub Desktop.
Process form via Ajax with multiple conditions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row" id="wrapper"> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<h4>Submit Information and Update Database</h4> | |
<form id="redeem" action="index.php" method="post"> | |
<div class="row"> | |
<div class="large-12 columns"> | |
<label for="fullname">Full Name<input type="text" name="fullname"></label> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="large-12 columns"> | |
<label for="email">Email<input type="email" name="email" id="email"></label> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="large-12 columns"> | |
<label for="email">Confirm Email<input type="email" name="confirmation"></label> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="large-12 columns"> | |
<label for="cardnumber">Cardnumber<input type="text" name="cardnumber"></label> | |
</div> | |
</div> | |
<input type="submit" class="simple button" name="submit"> | |
</form> | |
</div> | |
<div class="large-6 columns"> | |
<div class="large-12 columns"> | |
<h4>Give Cardholder Prize</h4> | |
<div class="panel"> | |
<?php | |
if (isset($_POST['submit'])) { | |
error_reporting(E_ALL); | |
ini_set('display_errors', '1'); | |
include('db-connect.php'); | |
$fullname = $_POST['fullname']; | |
$email = $_POST['email']; | |
$cardnumber = $_POST['cardnumber']; | |
$select = "SELECT * FROM cardholders WHERE cardnumber = $cardnumber"; | |
$selectfrom = mysql_query($select); | |
if ($info = mysql_fetch_assoc($selectfrom)) { | |
if ($fullname == $info['name'] && $info['used'] == 0) { | |
// To send HTML mail, the Content-type header must be set | |
$headers = 'MIME-Version: 1.0' . "\r\n"; | |
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; | |
// $headers .= 'CC: $email' . "\r\n"; | |
$headers .= 'From: Comanche Nation Casinos <no-reply@comanchenationcasinos.com>'; | |
$confirmation = '<h1>Hi ' . $info['name'] . ' you\'ve won <b>$' . $info['amount'] . '</b> in Comanche Credit!</h1> | |
<p>Thank you for being such a valuable C Club member. Print or Show this email and redeem this at your Comanche Nation Casino.</p> | |
<p>Save this email just incase something happens so that the staff can ensure your reward at the kiosk.</p>'; | |
mail($email, "Confirmation", $confirmation, $headers); | |
echo "<div class='result' style='display: none'><p>Congratulations!" . $info['name'] . "!</p> <p>You've won! Please check your email for your winnings and futher information.</div>"; | |
$updateUser = "UPDATE cardholders SET email='$email', used=1 WHERE cardnumber = $cardnumber"; | |
$update = mysql_query($updateUser); | |
} else if ($fullname != $info['name'] && $info['used'] == 0) { | |
echo "<div class='result' style='display: none'>Sorry but your name does not match the name in our database.</div>"; | |
} else { | |
echo "<div class='result' style='display: none'><p>Sorry but this offer has already been redeemed to this account</p></div>"; | |
} | |
} else { | |
echo "<div class='result' style='display: none'><p>Sorry but this card number does not exist.</p></div>"; | |
} | |
} | |
?> | |
</div> | |
</div> | |
<div class="large-12 columns"> | |
<h4>Show Status</h4> | |
<div class="panel"> | |
<p>Any Errors/Status Here</p> | |
</div> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment