我正在尝试为数据库中的用户添加点数。应该如何运作的方式如下: 当有人发送另一些积分时,它应计算当前余额并将积分添加给用户。
到目前为止,我尝试了但它一直发送空白数字,而mysql并没有将这些点加起来。
我还包括代码:
if(isset($_POST['points'], $_POST['user'])){
include_once("database_connect.php");
$points = mysqli_real_escape_string($database_connect, $_POST['points']);
$touser = mysqli_real_escape_string($database_connect, $_POST['user']);
$user = "someone";
$addup = "SELECT amount FROM points (SUM(amount)+SUM('$payment'))";
$sql = "INSERT INTO currency (amount, from, touser, datemade)
VALUES('$addup','$user','$touser','$datemade')";
$query = mysqli_query($database_connect, $sql);
echo "<h1>Thank You</h1><h2>Your payment has been made</h2>";
exit();}
&GT?;
对于网页:
<html>
<head>
</head>
<body>
<form name="form1" method="post" action="">
<label for="points">points</label>
<input type="text" name="points" id="points">
<label for="user">user</label>
<input type="text" name="user" id="user"><input name="submit" type="submit" value="submit">
</form>
</body>
</html>
我期待您的投入。
答案 0 :(得分:0)
尝试使用insert . . . select
:
$sql = "INSERT INTO currency(amount, from, touser, datemade)
SELECT SUM(amount)+SUM($payment), '$user','$touser','$datemade'
FROM points" ;
$ = mysqli_execute($database_connect, $sql);
原始查询的问题如下:
SELECT amount FROM points (SUM(amount)+SUM('$payment'))";
sum('$payment')
取一个常量字符串的总和。另外,