Hi,
I am kind of new to PHP, I looked around google and found what I was looking for (questionnaire to text) works perfectly fine with input type text and radio but when I try to do a checkbox it would not write the multiple answers on text file it would rather do one or return with an error. could someone please look at the script below and see what I am doing wrong?
<?php
if(isset($_POST['submit'])){
$firstName = "First Name:".$_POST['firstName']."
";
$lastName = "Last Name:".$_POST['lastName']."
";
$sex = "Sex:".$_POST['sex']."
";
$fruit = "Fav Fruits:".$_POST['fruit, fruit2, fruit3']."
";
$file=fopen("file.txt", "a");
fwrite($file, $firstName);
fwrite($file, $lastName);
fwrite($file, $sex);
fwrite($file, $fruit, $fruit2, $fruit3);
fclose($file);
}
?>
<form method="post">
Name<input type="text" name="firstName" placeholder="First Name" required autocomplete="off"> <br>
Last Name<input type="text" name="lastName" placeholder="Last Name" required autocomplete="off"> <br>
Sex<input type="radio" name="sex" value="male">Male
<input type="radio" name="sex" value="female">Female<br>
Fav Fruit<input type="checkbox" name="fruit" value="apple">Apple
<input type="checkbox" name="fruit2" value="orange">Orange
<input type="checkbox" name="fruit3" value="berry">Berry<br>
<input type="submit" name="submit" value="Submit">
</form>