dtup3446
2016-03-08 11:50
浏览 172
已采纳

解析数据时格式错误的JSON响应

Using Postman to see if this section of php works as intended, however Postman returns the error Malformed JSON: Unexpected 'U' and the database is not updated, can't get my head around this error as it looks fine to me?

Code:

function placeVoteForCandidate()
{
    global $connect;

    $username = $_POST["username"];

    $query = "UPDATE User SET votesAttained=votesAttained+1 WHERE USER_NAME = $username";

    mysqli_query($connect, $query) or die (mysqli_error($connect));
    mysqli_close($connect);

    $message['success'] = 'Vote added';
    echo json_encode($message);
}

图片转代码服务由CSDN问答提供 功能建议

使用Postman查看php的这一部分是否按预期工作,但Postman返回错误格式错误的JSON: 意外的'U'</ code>和数据库没有更新,无法理解这个错误,因为它看起来不错?</ p>

代码:</ p>

  function placeVoteForCandidate()
 {
 global $ connect; 
 
 $ username = $ _POST [“username”]; 
 
 $ query =“UPDATE User SET votesAttained = votesAttained  +1 WHERE USER_NAME = $ username“; 
 
 mysqli_query($ connect,$ query)或die(mysqli_error($ connect)); 
 mysqli_close($ connect); 
 
 $ message ['success']  ='投票已添加'; 
 echo json_encode($ message); 
} 
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题