Jump to content

Recommended Posts

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 

 

There is one directory layer difference between these two:

measured-response.com/leeds/study-info/demogstore.php

measured-response.com/study-info/demogstore.php

re: one layer of difference - that is really strange and I am not sure why - all the files are in the com/leeds/study-info/ directory but for some reason the ftp urls of all the files in that directory give com/study-info/ leaving out one layer.

 

When I want to access the files I use the .....com/leeds/study-info/file.html url and that allows me to access the first html file from which I then move in succession through all the other html files so the server seems to retrieve those without a problem.

 

Even the error that says that the php file isn't found is reporting the correct path to it so it seems that the server is looking in the right location (com/leeds/study-info/). Could it be an ftp issue then and is there something I can do to change what my ftp client thinks is the url-path?

According that one - com/leeds/study-info/ , your web root directory is called "com" .

 

Just move the study-info there.

 

PS. Do you see any index file in the "com" directory?

Edited by jazzman1

well I see in one of OP's first posts he says error is 18-Feb-2013 12:04:13 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/measured/public_html/leeds/study-info/demogstore.php on line 12

 

but in his Screenshot for firebug it is saying /home/measured/leeds/study-info/demogstore.php

 

notice the public_html?

of course I could be way off base here lol

Edited by dodgeitorelse3

Hi Jazzman, that's a good idea. I don't have access to the .com directory - I'm asking the server owner for permission. I'll move the /study-info folder there and let everyone know what happens.

 

@Dodge The error I posted previously is from the error log on my server but it's old.

Hi Jazzman, that's a good idea. I don't have access to the .com directory - I'm asking the server owner for permission. I'll move the /study-info folder there and let everyone know what happens.

 

@Dodge The error I posted previously is from the error log on my server but it's old.

 

I'm really confused what is the name of your web root directory of the server.

 

Just, phone and ask them for details that you need to know.

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.

Edited by psjtk

Hi jazzman, I inserted the code as you suggested.

 

<?php

// decode JSON string to PHP object
$timestamp = json_decode($_POST["timestamp"]);
$decoded = json_decode($_POST["json"], true);
echo '<pre>'.print_r($decoded, true).'</pre>;




$fp = fopen('PHP_data/'.$timestamp.'_data.csv', 'a');



foreach ($decoded as $fields) {
   fputcsv($fp, $fields);
}


fclose($fp);

?>

 

It creates a syntax error:

 

[20-Feb-2013 05:14:04] PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home1/asthmavi/public_html/demogstore.php on line 10

Ops.....sorry for my previous mistake.

 

Try,

 

<?php

// decode JSON string to PHP object
$timestamp = json_decode($_POST["timestamp"]);
$decoded = json_decode($_POST["json"], true);

echo '<pre>'.print_r($decoded, true).'</pre>'; exit;

$fp = fopen('PHP_data/'.$timestamp.'_data.csv', 'a');



foreach ($decoded as $fields) {
       fputcsv($fp, $fields);
}


fclose($fp);


This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.