PHP code still not working


I’ve posted this a couple of times now (thanks for your responses m@tt).

m@tt has said that he has tested my code and that there is nothing wrong with it; however, it is not sending the data from the webform to the .csv? Also, I forgot to mention previously, it is not displaying an error message when fields on the form are left blank; it just submits the form anyway?

Does anybody know why this might be?

Here is the code again:


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


    Any suggestions would be very much appreciated :frowning:

    I just copy and pasted your code again and I get a file called data.csv with the input values:

    My name, My occupation

    As I mentioned before you need to make sure the directory is writable (chmod) or the file itself is created and writable.

    Sponsor our Newsletter | Privacy Policy | Terms of Service