PHP page only sending commas to .csv

Hi all,

I posted this message yesterday and m@tt kindly responded to advise that it looks to be correct, but to check that the directory has write permissions. I have now checked this and it appears to be writable; saying this, I forgot to mention in my previous post that, although the data is not sent from the form to the .csv, the .csv is receiving something as it records the commas that would separate the data.

Just in case anybody can help me further, I have posted the code again below (I have remembered to use the ‘PHP’ button this time…sorry for forgetting on the last post!).

Thanks in advance!

Here it is:


Which is your name?
What is your occupation?
<?php if($_POST['formSubmit'] == "Submit") { $errorMessage = ""; if(empty($_POST['formName'])) { $errorMessage .= "
  • You forgot to enter your name!
  • "; } if(empty($_POST['formOccupation'])) { $errorMessage .= "
  • You forgot to enter your occupation!
  • "; } $varName = $_POST['formName']; $varOccupation = $_POST['formOccupation']; if(!empty($errorMessage)) { echo("

    There was an error with your form:

    \n"); echo("
      " . $errorMessage . "
    \n"); } } ?> <?php if($errorMessage != "") { echo("

    There was an error:

    \n"); echo("
      " . $errorMessage . "
    \n"); } else { $fs = fopen("data.csv","a"); fwrite($fs,$varName . ", " . $varOccupation . "\n"); fclose($fs); } ?>


    There was nothing wrong with your code before. I tested it on my localhost and it worked.

    Sponsor our Newsletter | Privacy Policy | Terms of Service