PHP page not sending data to .csv

Hi all,

I don’t suppose anybody can see an error in my PHP code below? It is supposed to send the form data to the .csv but isn’t doing :frowning:

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); } ?>

    The code looks fine to me. Make sure your directory has write permissions.

    Sponsor our Newsletter | Privacy Policy | Terms of Service