Jump to content

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.

Edited by Psycho

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 

Edited by KlappenVanJePa

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 = 'tymenw@Gmail.com';
$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';
}
} 
?>

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.