The error message that the OP cites relates to the very first statement:
int counter = 0;
in which the code attempts to declare a variable's type. However, PHP users don't need to do this nor should they because PHP determines a variable's type based on its value. However, if you eliminate "int", as follows:
counter = 0;
the code still errs out because in PHP, a variable's name consists of a bareword and a sigil in the form of a prepended dollar sign. The proper correction for the first statement is as follows:
$counter = 0;
Important: Always consider the data a user provides as suspect. Instead of directly using $_POST['FirstNum']
, one should check that it contains valid data. Consider the following solution:
<?php
if (isset($_POST['submit'])) {
$cleanFirstNum = (ctype_digit($_POST['FirstNum']) )? $_POST['FirstNum'] : "0";
$counter = 0;
while ($counter++ < 1) {
switch( $cleanFirstNum )
{
case "1":
echo "Addition";
break;
case "2":
echo "Subtraction";
break;
case "3":
echo "Multiplication";
break;
case "4":
echo "Division";
break;
default:
echo "Invalid Operation";
break;
}
}
}
?>
If $cleanFirstNum
is not numeric, then it acquires a value of zero and the default code runs.
Note that with the input element of type number you may specify minimum and maximum values to restrict the user's options. The backend code in this example assures that if anyone tampers with the form, you may avoid invalid data having a deleterious effect.
<html>
<head><title>testing</title></head>
<body>
<form action="" method = "POST">
Enter the first number: <input type="number" min="1" max="4" name="FirstNum" required><br><br>
<input type="submit" name="submit" value="Enter"/>
</form>
</body>
</html>
Finally, one last concern: should the OP's code use PHP or might JavaScript be more appropriate (see a related example here)?
Popular PHP resource: the Manual