Jump to content

Math question by a form don't work


KlappenVanJePa

Recommended Posts

Hello, 
 
I have set up a form but when I fill it in it says the captcha math question is wrong. 
I have checked everthing but I can't find my problem.

 

The strange thing that I get the error but It still sends a email. 

http://klappenvanjepa.co.nf/

<?php 
	
					$num_one = rand() % 10;
					$num_two = rand() & 10;
					$final_num = $num_one + $num_two;
					$_SESSION['answer'] = $final_num;
					echo $num_one . ' + ' . $num_two . ' = ';
					    ?>
    
    				
    				
   					<input type="text" name="answer" /> <br />
				
                        <input type="submit" name="send_message" value="Send!">		 

 

 

 

 

$user_answer = $_POST['answer'];
$real_answer = $_SESSION['answer'];



if(empty($naam) OR empty($email) OR empty($email)) {
	echo "Your forget somthing.";

} elseif($user_answer != $real_answer) {
	echo "Can't send because the question is wrong.";

 

Can someone please help me with this problem. 

 

Thanks 

 

Link to comment
https://forums.phpfreaks.com/topic/275333-math-question-by-a-form-dont-work/
Share on other sites

Are you using session_start() on both pages?

 

 

EDIT:

 

The strange thing that I get the error but It still sends a email.

 

You don't show enough code to see that problem. All you have is this

 

elseif($user_answer != $real_answer) {
    echo "Can't send because the question is wrong.";

 

If you close out that execution block and have code later on in the page to send the email, then that error handling would do nothing to prevent that. You need to ensure the email logic is only run if there are no errors.

Do a var_dump on both answers. What are they?

 

I am fairly new to php and I do not know what a var_dump is.

I've looked on google but I can not clearly find it there. And also I looked in your "debbugging  url but I still do not understand it". 

 

Can you please explain it otherwise. 

Thanks 

Are you using session_start() on both pages?

 

 

EDIT:

 

 

You don't show enough code to see that problem. All you have is this

 

elseif($user_answer != $real_answer) {
    echo "Can't send because the question is wrong.";

 

If you close out that execution block and have code later on in the page to send the email, then that error handling would do nothing to prevent that. You need to ensure the email logic is only run if there are no errors.

 

 

<?php

session_start();

$email = $_POST['email'];
$naam = $_POST['naam'];
$onderwerp = $_POST['onderwerp'];
$vragen = $_POST['vragen'];
$user_answer = $_POST['answer'];
$real_answer = $_SESSION['answer'];

if(empty($naam) OR empty($email) OR empty($email)) {
	echo "Uw bent iets vergeten in te vullen.";

} elseif($user_answer != $real_answer) {
	echo "can't send because the question is wrong.";
}

else {
	mail($to, $subject, $message, "From: $email");
	echo "Message sent";
}
$to = '[email protected]';
$subject = 'contact';

$body = <<<EMAIL

Naam: $naam
Email: $email
Onderwerp: $onderwerp
vragen: $vragen

EMAIL;

$header = ('Location: index.html');

if($_POST){
if($naam == ''|| $email == ''|| $vragen == '' ){
$feedback = 'U forget something';
}else{
mail($to, $subject,  $body, $header);
$feedback = 'Thanks The message has been sended';
}
} 
?>

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.