Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    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.

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    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.
    Get Cloud Hosting now from only£59 / month


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •