Hellow
I want to write data from api in MySql Database, I have api.js file to get the data from the api and a php file to write the data to MySql table;
api.js
$(function()
{
var $orders = $('#orders');
$.ajax({
type:'GET',
url:'http://datatank.stad.gent/4/cultuursportvrijetijd/gentsefeestenlocaties.json',
success: function(orders) {
dataType:'json', // add json datatype to get json
data: ({name: orders})
$.each(orders, function(i, order) {
$orders.append('<li>id: ' + order.id + ', ' + order.naam);
});
},
});
Following code is my php.file
<?php
define('DB_HOST', '');
define('DB_NAME', '');
define('DB_USER','');
define('DB_PASSWORD','');
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());
$myArray = $_GET['name'];
echo ($myArray);
print_r ($myArray);
echo ('Mattijs');
foreach ($myArray as $row)
{
echo($row[0]);
$query = mysql_query("INSERT INTO `straat`(`ID`, `StraatFeest`) VALUES ('" + $row[0] + "','" + $row[1] + "')") or die(mysql_error());
}
//$query = mysql_query("INSERT INTO `straat`(`ID`, `StraatFeest`) VALUES ('dd','dd')") or die(mysql_error());
$row = mysql_fetch_array($query) or die(mysql_error());
?>
myArray is still empty
I don't get data from the ajax File
Thanks