Jump to content

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?

Edited by ignace
Added code tags
Link to comment
https://forums.phpfreaks.com/topic/275751-try-to-make-a-question-with-variabels/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.