I been working on a code, where the user can access the promocode in DB along with discount that comes with it. Now when user has to pay and got a promocode, he enters the same and avails some discount in his pay. Now how to limit the promocode access to once?
My code goes as ::
<?php include('db.php'); ?>
<?php
$promocode = $_POST['promocode'];
$payamount = $_POST['payamount'];
$mobile = $_SESSION['mobile'];
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql3 = "SELECT * FROM apromocode WHERE code = '$promocode' ";
$result3 = $conn->query($sql3);
if ($result3->num_rows > 0) {
while($row3 = $result3->fetch_assoc()) {
$discount = $row3['discount'];
$total1 = $discount;
$total2 = $pay - $total1;
$sql = "UPDATE userpaytoget SET payamount = '$total2'
WHERE mobile = '$mobile'";
if ($conn->query($sql) === TRUE) {
echo '<script language="javascript">';
echo 'alert("PromoCode Applied")';
echo '</script>';
echo '<a href="user-profile.php"></a>';
}
else {
echo "ERROR" . $sql . "<br>" . $conn->error;
}
}
}
else {
echo "ERROR" . $sql3 . "<br>" . $conn->error;
}
$conn->close();
?>
Here, i get the payamount and promocode form user while i will check the promocode with the db and get the discount accordingly...
Now here, i dont have any restrictions for user where he can only avail this for once.. Any help is appreciated...