Jump to content

Try to make a question with variabels


bylletski

Recommended Posts

Hello I'm new in this forum but i hope you understand what I trying to do.

 

 

<?php
$theanswer = 4;
$answer = $_POST['answer'];

if(isset($_POST['button'])){

if ($theanswer = $answer){
echo "Right the answer is 4<br>";

} else {

echo "Wrong try again!";

}


}
?>
2 + 2 is?
<form method="post" action="new.php">
<input type="text" name="answer">
<input type="submit" name="button">
</form>
 

 

The code don't work and I get an notice too.

 

Notice: Undefined index: answer in C:\wamp\www\ss\new.php on line 4

 

I think you understand what i want but i will explain if you don't.

 

If they write 4 in the textfield the echo will say Right the answer is 4. But if they write anything else

it will say wrong try again!

 

Now i wonder what have i do wrong?

Link to comment
https://forums.phpfreaks.com/topic/275751-try-to-make-a-question-with-variabels/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.