I have some code that is supposed to increase a value in a database when a button is clicked. The value is gold, I want the gold to increase by 100 when the button is clicked. I get no error messages or anything but the gold just doesn't increase, I swear it all looks ok?
<?php
include("connect.php");
include("header.php");
$username = $_SESSION['userlogin'];
if(isset($_SESSION['userlogin'])){
$addgold2 = mysqli_query($con,"UPDATE stats.gold SET stats.gold = stats.gold + 100 WHERE users.username = '$username' AND stats.id = users.id");
if(isset($addgold2['submit'])){
}
}
echo "You have earned 100 gold!";
mysqli_close($con);
?>
You're referencing a column called users.username
inside an UPDATE query that is being applied against a table called stats
. You are also attempting to update a row?
Try adding some basic error checking:
$addgold2 = mysqli_query($con,"UPDATE stats.gold SET stats.gold = stats.gold + 100 WHERE users.username = '$username' AND stats.id = users.id");
if($addgold2 === false){
throw new Exception(mysqli_error($con));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.