I want to send some data from a jQueryMobil.listwidget via PHP to a mysql database.
I get and post my listitems like this:
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();
}
i want to add my json-object to a mysql database/table which exists. On my request my data is sent but the if(prepStmnt) never succeeds.
<?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();
?>
Can you please tell my why no data is stored in my db?