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: :frowning:](//dev.phphelp.70mad.com/images/emoji/twitter/frowning.png?v=5)
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("
\n");
}
}
?>
<?php
if($errorMessage != "")
{
echo("
There was an error:
\n");
echo("
\n");
}
else
{
$fs = fopen("data.csv","a");
fwrite($fs,$varName . ", " . $varOccupation . "\n");
fclose($fs);
}
?>