嗨我有一个MySQL数据库表"点"用户可以点击一个按钮,一个点应该从他们的帐户中删除,他们按下的按钮有另一个用户的ID,因此他们的帐户必须增加一个.
我让它在jQuery中工作并检查Firebug中的varibles/posts,它确实发送了正确的数据,例如:
userid= 1
posterid = 4
Run Code Online (Sandbox Code Playgroud)
我认为问题出在我的PHP页面上:
<?php
include ('../functions.php');
$userid=mysql_real_escape_string($_POST['user_id']);
$posterid=mysql_real_escape_string($_POST['poster_id']);
if (loggedin())
{
include ('../connection.php');
$query1 = "UPDATE `points` SET `points` = `points` - 1 WHERE `userID` = '$userid'";
$result1=mysql_query($query1);
$query2 = "UPDATE `points` SET `points` = `points` + 1 WHERE `userID` = '$posterid'";
$result2=mysql_query($query2);
if ($result1 && result2)
{
echo "Successful";
return 1;
}
else
{
echo mysql_error();
return 0;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢 :)
acm*_*acm 76
增加/减少字段值的两个查询不是必需的:
mysql_query("UPDATE table SET field = field + 1 WHERE id = $number");
Run Code Online (Sandbox Code Playgroud)
是一个完全有效的查询,你可以看到下一个:
mysql> describe points;
+--------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------+------+-----+---------+-------+
| uid | int(11) | NO | PRI | NULL | |
| points | int(11) | YES | | 0 | |
+--------+---------+------+-----+---------+-------+
2 rows in set (0.05 sec)
mysql> insert into points VALUES (1,0),(2,0);
Query OK, 2 rows affected (0.14 sec)
mysql> select * from points;
+-----+--------+
| uid | points |
+-----+--------+
| 1 | 0 |
| 2 | 0 |
+-----+--------+
2 rows in set (0.05 sec)
mysql> update points set points = points+1 where uid = 1;
Query OK, 1 row affected (0.27 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from points;
+-----+--------+
| uid | points |
+-----+--------+
| 1 | 1 |
| 2 | 0 |
+-----+--------+
2 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
经过测试,你确定你会进入你的if (loggedin())条款吗?
我必须同意KM,很高兴看到echo $query1;或的输出echo $query2;
小智 5
以下是我测试的示例查询,它正在100%工作
$query="UPDATE table_name SET `hit_count`=(`hit_count`+1) WHERE `id` = '1'";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
76894 次 |
| 最近记录: |