我已经在php中制作了一个游戏,人们可以通过这些游戏升级他们的东西,这些钱将从他们的帐户中扣除。但是当货币价值变低时,货币价值就会减去,货物会升级。这是代码:
<?php
session_start();
include_once 'dbconnect.php';
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dbtest";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
?>
</html>
<head>
<body bgcolor="black">
<?php echo "<font color=\"#49fb35\" size=\"5\">Update Firewall Software $300</font><br>"; ?>
<a href="firewall.php"><font color="#49fb35" size="5">Upgrade Firewall.exe for $300</font></a>
</head>
</html>
如果货币价值低,如何停止升级?
答案 0 :(得分:2)
您可以使用PHP来验证该值是否大于0,使用:
$query1 = "SELECT * from users WHERE user_id=".$_SESSION['user'];
$result = mysql_query($query1);
while($row = mysql_fetch_array($result)) {
// Get money from column
$money = $row['money'];
}
if($money >= 300) {
$query = "UPDATE users SET firewall = firewall + 1, money = money - 300 WHERE user_id=".$_SESSION['user'];
$update = mysqli_query($conn,$query);
} else {
// Prints error
echo 'Money is not enough to upgrade';
}
我不确定你使用的是什么变量名,你可以相应地改变,希望这有帮助!