0

我的代码运行良好,除了“用户名”,由于某种原因,通过 JSON 发送字符串不会发布到表,它什么也不发送。

任何人都可以看到问题是什么?

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
4

1 回答 1

2

你为什么用这个:

$userName = $obj = json_decode($_GET['userName']);

它工作正常

$userName = $_GET['userName'];
于 2012-07-27T12:17:48.183 回答