Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
// membuat koneksi
$con = mysqli_connect('localhost','root','');
mysqli_select_db($con,"coupon_test");
// set kode kupon
$code = "CQ839";
// dapatkan info kupon berdasarkan kode
$sql = "SELECT * FROM kupon WHERE code = '$code'";
$res = mysqli_query($con,$sql);
$row = mysqli_fetch_assoc($res);
// lakukan update jika usage < max_usage
if($row['usage'] < $row['max_usage']){
$sql = "UPDATE kupon SET usage = usage + 1 WHERE code = '$code'";
mysqli_query($con,$sql);
echo "BERHASIL";
}else{
echo "GAGAL";
}
// menutup koneksi
mysqli_close($con);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.