Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-18-2013, 03:45 PM   PM User | #1
psjtk
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
psjtk is an unknown quantity at this point
Angry HELP: Server Can't Find PHP file

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:


Code:
//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 Code:
<?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?
psjtk is offline   Reply With Quote
Old 02-18-2013, 05:35 PM   PM User | #2
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
what exactly is the error or is it a warning or notice. Is it that the file cannot be found or the fopen failed.

Please post the extact message you are getting, take out anything personal from the notice for security of course.

Is it that the fopen failed check permission. And also check your ini to make sure you are not blocking it.

Also i think if you called a php file with javascript its a javascript question not a php question.
durangod is offline   Reply With Quote
Old 02-19-2013, 02:09 PM   PM User | #3
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 597
Thanks: 15
Thanked 67 Times in 67 Posts
Arcticwarrio is on a distinguished road
can you echo $decoded;

PHP Code:

$decoded 
json_decode($_POST["json"]);
echo 
$decoded;
//may need
print_r ($decoded); 
what does it output?
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
Arcticwarrio is offline   Reply With Quote
Reply

Bookmarks

Tags
php; javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:51 PM.


Advertisement
Log in to turn off these ads.