我正在尝试创建一个积分系统,您可以从中选择1到5
<form class='form-horizontal' action='../api/points.php' method='post'><fieldset>
<input type='radio' value='1' name='points' /> 1 </input>
<input type='radio' value='2' name='points' /> 2 </input>
<input type='radio' value='3' name='points' /> 3 </input>
<input type='radio' value='4' name='points' /> 4 </input>
<input type='radio' value='5' name='points' /> 5 </input>
<br />
<input name='Submit' type='submit' value='give points' />
<input name='userid' type='hidden' value='<? echo $row['user_id'] ?>' />
<input name='postid' type='hidden' value='<? echo $row['id'] ?>;' />
<input name='currentpoints' type='hidden' value='<? echo $row['postpoints']; ?>' />
<input name='user2id' type='hidden' value='<? echo $loggedInUser->user_id; ?>' />
</fieldset>
</form>
有两个id,即给定点的用户的id以及将接收它们的用户的id。
我必须存储它们:(1)在posts表上,它记录了发布的总点数。 (2)积分应从提供给用户的用户中减去并添加到发布它的用户。
它为帖子提供了分数,但它没有添加或减少用户表
$pointsvar = htmlentities($_POST['points']);
$userid = htmlentities($_POST['userid']);
$user2id = htmlentities($_POST['user2id']);
$postid = htmlentities($_POST['postid']);
$currentpoints = htmlentities($_POST['currentpoints']);
$suma1 = $currentpoints+$pointsvar;
$sql = "UPDATE ft_posts SET postpoints=(postpoints + $pointsvar) WHERE id='$postid'";
if ($conn->query($sql) === TRUE) {
echo "post points updated successfully";
echo "<br />";
echo "current post points+points variable: ";
echo ($suma1);
echo "<br />";
} else {
echo "Error updating record: " . $conn->error;
}
$sql2 = "UPDATE ft_users SET points='(points + $pointsvar)' WHERE id='$userid'";
if ($conn->query($sql2) === TRUE) {
echo "User given points updated successfully";
echo "<br />";
} else {
echo "Error updating record 2: " . $conn->error;
}
$sql3 = "UPDATE ft_users SET points='(points - $pointsvar)' WHERE id='$user2id'";
if ($conn->query($sql2) === TRUE) {
echo "User taken points updated successfully";
echo "<br />";
} else {
echo "Error updating record 3: " . $conn->error;
}$conn->close();
答案 0 :(得分:1)
删除points='(points + $pointsvar)'
中的引号
并为SET points='(points - $pointsvar)'
关于这一行:
if ($conn->query($sql2) === TRUE) {
您正在将其与$sql3
结合使用,因此应该是:
if ($conn->query($sql3) === TRUE) {