Skip to content

Instantly share code, notes, and snippets.

@radityopw
Last active February 15, 2017 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radityopw/824d16d320390a648461facb43d08220 to your computer and use it in GitHub Desktop.
Save radityopw/824d16d320390a648461facb43d08220 to your computer and use it in GitHub Desktop.
<?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