Captcha code does not work

I’m having a problem with captcha code. I keep getting the echo message “CAPTCHA CODE does not match!” everytime I send it . What am I not seeing? Please open my eyes to the error. Thanks in advance.

[php]<?php
session_start();

include “config.php”;
$id = (int)$_GET[‘id’];
$res = mysql_query($query, $bd);
$id = (int)$_GET[‘id’];
$id = substr($id, 0,5);
if($id < 1 || $id > 99999) exit;
$query = “SELECT * FROM units WHERE id = $id”;
$res = mysql_query($query, $bd);
$result = mysql_fetch_assoc($res);
$contact = $result[‘contact’];
$phone = $result[‘phone’];

$var = $result[‘email’];
if (!empty($var)) {
if (isset($_POST[‘submit’])) {
if(($_SESSION[‘security_code’] == $_POST[‘security_code’]) && (!empty($_SESSION[‘security_code’])) ) {
$to = “$var”; // change to your email address
$name = htmlentities ($_POST[‘name’]);
$email = htmlentities ($_POST[‘email’]);
$phone = htmlentities ($_POST[‘phone’]);
$msg = htmlentities ($_POST[‘msg’]);
$d = date(‘l dS \of F Y h:i:s A’);
$sub = “My Domain RE:”.$result[‘title’]."";
$headers = “From: $name <$email>\n”;
$headers .= “Content-Type: text/plain; charset=iso-8859-1\n”;
$mes = “phone: “.$phone.”\n”;
$mes .= “Message: “.$msg.”\n”;
$mes .= “Name: “.$name.”\n”;
$mes .= 'Email: '.$email."\n";
$mes .= 'Date & Time: '.$d;
mail($to, $sub, $mes, $headers);

echo “<div align='left’Email Has Been Sent”;
} else {

echo "<div align='left’CAPTCHA CODE does not match! ";

}
	} 

echo "

Email: “.$result[‘contact’].”




captcha



";}?>[/php]

I realy didn’t solve it but I took the alternative route which the script requests an answer:

[php]<?php
session_start();

include “config.php”;
$id = (int)$_GET[‘id’];
$res = mysql_query($query, $bd);
$id = (int)$_GET[‘id’];
$id = substr($id, 0,5);
if($id < 1 || $id > 99999) exit;
$query = “SELECT * FROM units WHERE id = $id”;
$res = mysql_query($query, $bd);
$result = mysql_fetch_assoc($res);
$contact = $result[‘contact’];
$phone = $result[‘phone’];

$var = $result[‘email’];
if (!empty($var)) {
if (isset($_POST[‘submit’])) {
if(($_SESSION[‘security_code’] == $_POST[‘security_code’]) && (!empty($_SESSION[‘security_code’])) ) {
$to = “$var”; // change to your email address
$name = htmlentities ($_POST[‘name’]);
$email = htmlentities ($_POST[‘email’]);
$phone = htmlentities ($_POST[‘phone’]);
$msg = htmlentities ($_POST[‘msg’]);
$d = date(‘l dS \of F Y h:i:s A’);
$sub = “My Domain RE:”.$result[‘title’]."";
$headers = “From: $name <$email>\n”;
$headers .= “Content-Type: text/plain; charset=iso-8859-1\n”;
$mes = “phone: “.$phone.”\n”;
$mes .= “Message: “.$msg.”\n”;
$mes .= “Name: “.$name.”\n”;
$mes .= 'Email: '.$email."\n";
$mes .= 'Date & Time: '.$d;
mail($to, $sub, $mes, $headers);

echo “<div align='left’Email Has Been Sent”;
} else {

echo "<div align='left’CAPTCHA CODE does not match! ";

}
	} 

echo "

Email: “.$result[‘contact’].”




captcha



";}?>[/php]

Sorr I did this:

[php]

<?php $var = $result['email']; if (!empty($var)) { if (isset($_POST['submit'])) { if(isset($_POST['answer']) && $_POST['answer'] == '2'){ $to = "$var"; // change to your email address $name = htmlspecialchars ($_POST['name']); $email = htmlspecialchars ($_POST['email']); $phone = htmlspecialchars ($_POST['phone']); $msg = htmlspecialchars ($_POST['msg']); $d = date('l dS \of F Y h:i:s A'); $sub = "My Domain RE:".$result['title'].""; $headers = "From: $name <$email>\n"; $headers .= "Content-Type: text/plain; charset=iso-8859-1\n"; $mes = "phone: ".$phone."\n"; $mes .= "Message: ".$msg."\n"; $mes .= "Name: ".$name."\n"; $mes .= 'Email: '.$email."\n"; $mes .= 'Date & Time: '.$d; mail($to, $sub, $mes, $headers); echo "<div align='center'Email Has Been Sent"; } else { echo "<div align='center'ANSWER does not match! "; } } echo "
Email: ".$result['contact']."




What is 2 + 2?
Answer:



";}?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service