Last active
February 15, 2017 05:59
-
-
Save radityopw/824d16d320390a648461facb43d08220 to your computer and use it in GitHub Desktop.
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
<?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