我想发送一些数据从jQueryMobil.listwidget通过PHP到mysql数据库。
我获取并发布我的列表标题,如下所示:
function getItems()
{
var listview_array = new Array();
$( "#itemList li" ).each(function(index) {
listview_el = new Object();
listview_el.id = index;
listview_el.name=$(this).text();
listview_el.owner="owner";
listview_array.push(listview_el);
});
var stringifyObject = JSON.stringify(listview_array);
//alert(stringifyObject);
$.ajax({
type: "POST",
dataType: 'json',
url: "insert.php",
data: { mydata: stringifyObject },
});
//showItems();
}
我想将json-object添加到已存在的mysql数据库/表中。在我的请求中,我的数据被发送了,但是if(prepStmnt)从未成功。
<?php
$con = new mysqli($servername, $username, $password, $dbname);
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
echo "preps";
if($preparedStatement = $con->prepare('INSERT INTO Einkaufsliste (item, owner) VALUES (:name, :owner)')){
$preparedStatement->execute(json_decode($_POST["mydata"], true));
$preparedStatement->close();
echo "done";
};
$con->close();
?>
你能告诉我为什么我的数据库里没有数据吗?
https://stackoverflow.com/questions/27237023
复制相似问题