我的代码很好,除了“userName”,由于某些原因通过JSON发送字符串不会发布到表,它什么都不发送。用json发送字符串到php
任何人都可以看到什么问题是?
jQuery的
lowestScoreId = 1;
userPoints = 50;
userName = "ted";
$.getJSON("functions/updateHighScores.php", {lowestScoreId: lowestScoreId, userPoints: userPoints, userName: userName}, function(data) {
$('#notes').text(data.userName); //for testing
});
PHP
lowestScoreId = json_decode($_GET['lowestScoreId']);
$userName = json_decode($_GET['userName']);
$userPoints = json_decode($_GET['userPoints']);
include 'config.php';
$currentTime = time();
mysql_query("UPDATE highScores
SET `name` = '$userName',
`score` = '$userPoints',
`date` = '$currentTime'
WHERE id='$lowestScoreId'");
echo json_encode(array("userName" => $userName)); // for testing
我看不到'$ obj'的任何用法。 – Leri 2012-07-27 11:58:50
我想你已经把它混淆了......应该有一个JSON对象不是三个发送的?它应该像'$ obj = json_decode($ _ GET ['jsonObj'])'和其他从JSON对象中取得的值。另一件事......你并没有清理你的输入,并直接输入你的MySQL数据库。 – Ozzy 2012-07-27 12:01:07
嗯,好吧。感谢提示。我仍然有点新,所以在这一点上让事情发挥作用。 – user1555800 2012-07-27 12:02:26