Hi guys,
as the title specifies, my hosting provider does not have support for json_decode, so I need to find a way to adapt my code to achieve the same effect, but without using JSON, here is my code,
jQuery:
var allLocations = [];
$(".locations").each( function(i, location) {
// for each location block
location = $(location);
var loc = {
'province' : $("select[data-loc*='province']", location).val(),
'town' : $("select[data-loc*='town']", location).val()
};
allLocations.push( loc );
});
//POST the locations information
$.ajax({
type: 'POST',
url: 'locations.php',
dataType: 'json',
data: { locations: JSON.stringify(allLocations), uid: uid },
success: function(data){
//alert(data)
}
});
PHP:
$json = $_POST['locations'];
$uid = $_POST['uid']; // $json is a string
$json_array = json_decode($json, true);
mysql_connect('localhost','user','pass') or die(mysql_error());
mysql_select_db('eskom_products') or die(mysql_error());
//insert the locations into the database
while($json_array as $key){
$query = mysql_query("INSERT INTO suppliersLocations (supplier_id, province, town) VALUES('".$uid."', '".$key['province']."', '".$key['town']."' ) ") or die(mysql_error());
}
echo $text;
So as you can see, I am getting the province and town values of each location and creating a JSON object with it, which I then send off via $.ajax
to a PHP file, but now since json_decode
doesn't work, I need to try and find another way of fixing the problem, I was thinking of trying to pass an associative array to the php file, but I wanted to see what your guy's input would be, and if there might be a better way of achieving the desired result.
Thanx in advance!