psjtk Posted February 18, 2013 Share Posted February 18, 2013 Hi, I have an html page with a form that people fill out and when they press 'submit' I use a POST php method to save the information they entered onto a .csv file in the directory in my server. The php code is in a separate file that I call from the HTML page. However, I'm getting a 404 error saying that the php file which handles all that input cannot be found. 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 email = document.demographics.email.value; var demogs = [[age, freq, time, eng, email]]; var JSONdemogs = JSON.stringify(demogs); var postArray = {timestamp:timestamp, json:JSONdemogs}; if (document.demographics.email.value.length > 0){ $.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) } ) } }; THE PHP FILE LOOKS LIKE THIS <?php // decode JSON string to PHP object $timestamp = json_decode($_POST["timestamp"]); $decoded = json_decode($_POST["json"]); $fp = fopen('PHP_data'.$timestamp.'_data.csv', 'a'); foreach ($decoded as $fields) { fputcsv($fp, $fields); } fclose($fp); ?> The file path and the file name are correct. Does anyone know what could be causing this error? Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/ Share on other sites More sharing options...
jazzman1 Posted February 18, 2013 Share Posted February 18, 2013 Well, what values do you get to $timestamp and $decoded variables when the form has been submitted? You know that timestamp is a dynamic value, right? Example: // decode JSON string to PHP object $timestamp = json_decode($_POST["timestamp"]); $decoded = json_decode($_POST["json"]); echo $timestamp.' '. $decoded; Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413135 Share on other sites More sharing options...
psjtk Posted February 18, 2013 Author Share Posted February 18, 2013 I get a string of numbers or characters Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413152 Share on other sites More sharing options...
jazzman1 Posted February 18, 2013 Share Posted February 18, 2013 If I understand you correctly , you want every time to append a new content to the same directory and file name, right? But....actually the name of that directory would be change every time b/s of the timestamp. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413169 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 Yes I want to create a csv file that has timestamp as its name so that each person who fills out the questionnaire has a unique ID and then append data to that file. While timestamp is a changing value, I make a variable equal to one particular value of it so it should not be changing. In fact, this way of doing things has worked for me in the past and I pass the timestamp value on with the url as a query and that has not posed any problems. All the variable values that I get from the form seem to be in order, my unique problem is that the server tells me it cannot find the php file that I wrote to handle the recording of all that data which is strange because the file exists and it sits in the same directory as all the other files and even the path to it that is displayed when the error shows is correct. My question is, what could cause the server to fail to find the file? Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413316 Share on other sites More sharing options...
jazzman1 Posted February 19, 2013 Share Posted February 19, 2013 That's very weird, b/s the file is not php, the file format is CSV! Could you show us the entire error, please. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413324 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 Hi Jazzman, thanks for the quick reply!! I post the data to a php file within which I tell it to create a csv file to which the data is then appended. The error simply says: POST directory/ filename.php not found 404 thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413326 Share on other sites More sharing options...
jazzman1 Posted February 19, 2013 Share Posted February 19, 2013 Well, check for empty space after or before a "/" symbol. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413327 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 Hmm.. there aren't any spaces in between the directory and file name. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413328 Share on other sites More sharing options...
AyKay47 Posted February 19, 2013 Share Posted February 19, 2013 Since you are using a relative file path to demogstore.php, make sure that demogstore.php and the html file that is sending the form data to it are in the same directory. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413334 Share on other sites More sharing options...
jazzman1 Posted February 19, 2013 Share Posted February 19, 2013 (edited) We could not help you if you do not post entire error log string coming from the server. Edited February 19, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413335 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 Hi @jazzman1, here is the string I get from server: 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 @AyKay47 - yep, both files are in the same directory. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413336 Share on other sites More sharing options...
AyKay47 Posted February 19, 2013 Share Posted February 19, 2013 I thought the initial problem was that the called php file was not found? The foreach error is being triggered because you are passing the construct an object instead of an array. By default, if json_decode() is passed an object, it returns an object unless the second "assoc" parameter is set to TRUE. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413339 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 I admit that I am a bit new to this all. The error I posted previously is from the error log on my server but it's old. I set the assoc parameter to TRUE and that didn't change anything. I use firebug for troubleshooting and that is where it tells me that the server cannot find the php file which I believe to be the actual issue. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413342 Share on other sites More sharing options...
AyKay47 Posted February 19, 2013 Share Posted February 19, 2013 This is starting to make little sense to me, you say that the handling PHP file cannot be found, yet the parser is spitting out errors which means that the script is being executed. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413352 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 Hey, sorry for the confusion. The log error is an old error from yesterday when there wasn't a problem with the php file being found and the script was being executed but this no longer happens. So, right now there is only that one problem and that is that the server cannot find the php file. But that is one of the things that I find very confusing, since the php file was accessed fine at one point and then suddenly it stopped working and I can't figure out what could have caused it. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413357 Share on other sites More sharing options...
AyKay47 Posted February 19, 2013 Share Posted February 19, 2013 Have you double checked the permissions of the file? Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413362 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 Yes, all the permissions are set to read, write, and execute. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413365 Share on other sites More sharing options...
jazzman1 Posted February 19, 2013 Share Posted February 19, 2013 Can you give us the error which is spitting out from firebug, just copy/paste it to here, without any editing. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413366 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 This is the feedback that I'm getting: Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413374 Share on other sites More sharing options...
jazzman1 Posted February 19, 2013 Share Posted February 19, 2013 Well, that page is not located in this directory. Check this out: http://measured-response.com/leeds/study-info/demogstore.php Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413379 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 Hi jazzman, demogstore is in the directory. See this: Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413381 Share on other sites More sharing options...
jazzman1 Posted February 19, 2013 Share Posted February 19, 2013 yep, but where is the study-info directory? Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413384 Share on other sites More sharing options...
psjtk Posted February 19, 2013 Author Share Posted February 19, 2013 Hi jazzman, the error I'm getting is recording a correct file path. The file path is http://measured-response.com/leeds/study-info/demogstore.php It seems like the error is saying file does not exist in the folder /study-info, but the file is there. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413386 Share on other sites More sharing options...
jazzman1 Posted February 19, 2013 Share Posted February 19, 2013 Ok, see the path which your ftp client gives you to this particular file and post it here, please. Quote Link to comment https://forums.phpfreaks.com/topic/274628-server-cant-find-php-file/#findComment-1413387 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.