I'm trying to create a program that will ask the user to choose between two questions, do calculations on the results, then display those results to the user. For some reason my program is not working . Please help me with my problem. My code is below:
Code:
<?php
$answerYes = null;
$answerNo = null;
global $answer;
if (isset($_POST['submit'])){
$answer = $_POST['answer'];
echo $answer;
if ($answer == 'Yes'){
$answerYes = file_get_contents('answerYes.txt') or die('ERROR: Cannot find file');
$answerYesTwo = (integer) $answerYes;
++$answerYesTwo;
file_put_contents('answerYes.txt',(string)$answerYesTwo) or die ('ERROR: Cannot write file');
echo "<p =\"choice\">Your choice was submitted</p>";
}
else if ($answer == 'No'){
$answerNo = file_get_contents('answerNo.txt') or die('ERROR: Cannot find file');
$answerNo = (integer) $answerNo;
++$answerNoTwo;
file_put_contents('answerNo.txt',(string)$answerNoTwo) or die ('ERROR: Cannot write file');
echo "<p =\"choice\">Your choice was submitted</p>";
}
}
if (!isset($_POST['submit'])){
echo "<form action=\"Test.php\" method=\"post\">";
echo "<input type=\"radio\" name=\"answer\" value=\"Yes\">Yes</input>";
echo "<input type=\"radio\" name=\"answer\" value=\"No\">No</input><br>";
echo "<button type=\"submit\">Submit</button>";
echo "</form>";
}
Thanks,
Truck35