Answer the question
In order to leave comments, you need to log in
Why is it always an error, even when entering the correct number?
<html>
<head>
<meta charset="utf-8">
<title>Bender Rodriguez v.0.1</title>
</head>
<body>
<h1>Bender v.0.1</h1>
<p>Сыграем?</p>
<img id="Bender" src="http://diabloprint.ru/img/Bender_Rodriguez.png" alt="Bender"><br>
<?php
$numOne = rand(1,10);
$numTwo = rand(1,10);
$answer = $numOne + $numTwo;
echo ('Ответ:');
echo($answer);
echo ('<br>Сколько будет:');
echo ($numOne);
echo (' + ');
echo ($numTwo);
echo ('<br>Мой ответ:');
echo htmlspecialchars($_POST["answerUser"]);
if($answerUser===$answer) // or if(call())
{
echo('<br>Правильно');
}
else
{
echo('<br>Неправильно');
}
$answered = $answer;
?>
<form method="post" action="index.php">
<input name="answerUser" type="text" maxlength="20" size="25" value="" />
<input type=submit value="Ответить"></form>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
$answerUser===$answer must match types, most likely in this scenario answer is of type Number and answerUser is String
so either use == or explicitly cast to Number of type
1*$answerUser === $answer
htmlspecialchars($_POST["answerUser"]) most likely casts a number to a string
if($answerUser===$answer) - three = this is equal, given the type (integer or string).
Either the string must be converted to an integer or replaced with ==. Better first.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question