I am trying to pass multiple arrays to my script and from there I will insert these array values in database. In Branches_Control.php I want to save these array values in PHP variables and then pass them to my model and loop through that PHP array variable to insert
them in the DB.
This is my AJAX request:
var finalplaces = [];
var finallongArr = [];
var finallatArr = [];
var finalphone = [];
var finalcompanyName = [];
for (var i = 0; i < places.length; i++) {
if (finalplaces[i] != null) {
finalplaces[i].push(places[i])
finallongArr[i].push(longitudeArr[i]);
finallatArr[i].push(latitudeArr[i]);
finalphone[i].push(phone[i]);
finalcompanyName[i].push(companyName[i]);
}
}
$.ajax({
type: 'POST',
url: "Branches_Control.php",
data: "Places=" + finalplaces +
"&longitudeArr=" + finallongArr +
"&latitudeArr=" + finallatArr +
"&phones=" + finalphone +
"&companyNames=" + finalcompanyName,
success: function(data) {
alert(data + "Succese");
document.getElementById("asd").innerHTML = data;
}
});
What I am trying to do in my Branches_Control.php
$places = $_POST['Places'];
echo $places[0];
Can anyone tell me why this does not work?
$_POSTin original code. If not, this is the problem you're looking for. Any way useprint_r($_POST);and take a look what's inside.Array ( [Places] => [longitudeArr] => [latitudeArr] => [phones] => [companyNames] => )the values are not there can you tell me why?