[英]Inserting JSON object into MySQL table with Angular/PHP
So I have a JSON object I want to insert into a field in a MySQL table. 所以我有一个JSON对象,我想将其插入MySQL表的字段中。 When I do a "console.log(thatjson)", it prints the JSON object in the console with the text [Object], with all the information available when you click on the object.
当我执行“ console.log(thatjson)”时,它将在控制台中显示带有文本[Object]的JSON对象,并在单击该对象时提供所有信息。 However, when I do a "alert(thatjson)" it prints "object Object" in the alert box, and when I check that table in phpMyAdmin, the field which is varchar(2000) only stored a string which says [object Object].
但是,当我执行“ alert(thatjson)”操作时,它会在警报框中打印“ object Object”,并且当我在phpMyAdmin中检查该表时,varchar(2000)字段仅存储了一个字符串,该字符串表示[object Object] 。
In my php, i have $property = json_decode($request->getBody()); 在我的PHP中,我有$ property = json_decode($ request-> getBody()); to decode the angular passed json data, apparently that did not help.
解码角度传递的json数据,显然没有帮助。 : (
:(
Any ideas? 有任何想法吗?
Edit: 编辑:
Relevant Code: 相关代码:
$scope.update = function(thatjson){
$http.put('api/envisiondb/0', thatjson).success(function(data) {
$scope.properties = data;
});
};
PHP Slim: PHP Slim:
function editProperty($id) {
$request = Slim::getInstance()->request();
$property = json_decode($request->getBody());
$sql = "UPDATE db SET username=:username..."
The JSON object is just a regular everyday JSON object JSON对象只是日常的常规JSON对象
确保您通过JSON.stringify()
函数传递请求数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.