So just to update everyone on what happened. This is a project I'm working on at a university. The server is owned by someone who has allowed me to use it for this project, but I don't have access to the web root directory.
So, I uploaded the the files to a new server in the web root directory. I no longer have the issue that Jessica and everyone else pointed to, re: the missing of a layer in the path. I'm reposting my code below:
This is the Javascript on the html document that gets all the values from the form when the submit button is pressed:
//FUNCTION: Button press
var demogCont = function(){
var timestamp = new Date().getTime();
var age = document.getElementById('age').value;
var freq = document.demographics.item1.value;
var time = document.demographics.item2.value;
var eng = document.demographics.eng.value;
var demogs = [[age, freq, time, eng]];
var JSONdemogs = JSON.stringify(demogs);
var postArray = {timestamp:timestamp, json:JSONdemogs};
$.post("demogstore.php", postArray,
function(){
window.open('demographics2.html?demog=true&ts='+ timestamp,'_self',false);
}
)
.error(
function(){
alert('Communication error with server.');
window.open('demographics2.html?demog=true&ts='+ timestamp,'_self',false)
}
)
};
This is the PHP file, with the assoc parameters set to TRUE as AyKay recommended.
<?php
// decode JSON string to PHP object
$timestamp = json_decode($_POST["timestamp"]);
$decoded = json_decode($_POST["json"], true);
$fp = fopen('PHP_data/'.$timestamp.'_data.csv', 'a');
foreach ($decoded as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
?>
The PHP file now creates the .csv files, but my issue is that the csv files are now empty. It's not posting the values it gets from the HTML file.
Here is the error I get from my server:
[20-Feb-2013 03:38:10] PHP Warning: Invalid argument supplied for foreach() in /home1/asthmavi/public_html/demogstore.php on line 12
Any ideas? Thank you again, everyone who has been trying to help.