Hi all,
I have this form page as sidees.php file that sends to itself but it shows the error “You have introducted an invalid code. Please click here and try again”
as the code is not present. How do I make this conditional? Thanks!

$lastpage = $_SERVER['HTTP_REFERER']; 

if (($_SESSION['6_letters_code'] == $_POST['6_letters_code']) && !empty($_SESSION['6_letters_code'])) {
    $error = FALSE;
    if (!preg_match('/\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*/', $email)) {
        echo '<h4>Invalid email address</h4>';
        $error = TRUE;

    if ($name == '') {
        echo '<h4>No name</h4>';
        $error = TRUE;

    if ($email_subject == '') {
        echo '<h4>No subject</h4>';
        $error = TRUE;

    if ($message == '') {
        echo '<h4>No message</h4>';
        $error = TRUE;
    if ($error === FALSE) {
        $to = '';
        $name = $_POST['name'];
        $email_subject = $_POST['email_subject'];
        $message = $_POST['message'];
	$from = '';
        $email_body = <<<MSG
You have received a new message from $name

Here is the message:
Name: $name
Subject: $email_subject
Message: $message
Body: $email_body


        mail($to, $email_subject, $email_body);

        echo '<p>Your message has been sent correctly.</p>';
} else {
 echo "<p>You have introducted an invalid code. Please <a href=\\"$lastpage\\">click here and try again</a></p>";   
	<div id="sidebar">
		<br /><br /><br /><br /><br />
<div class="block" id="fyi">
		<h3 class="head">Header</h3>
	  <div class="block-content">
		 <form method="POST" name="contact_form" action="sidees.php"> 
Name: <input type="text" name="name"><br> 
Subject: <input name="email_subject" type="text"><br> 
Email: <input type="text" name="email"><br> 
Message: <textarea name="message" style="width: 144px">

<img src="captcha_code_file.php" /><br>
Enter your code here<input id="6_letters_code" name="6_letters_code" type="text" ><br>
<input type="submit" value="Enviar"><br>

Well obviously this line is failing:
if (($_SESSION[‘6_letters_code’] == $_POST[‘6_letters_code’]) && !empty($_SESSION[‘6_letters_code’])) {

You need to make it pass.

Thanks Alien so how do I do that? Cheers

You wrote the line, not me. I don’t know what your code is supposed to do.

What I want it to do is not show the message. So I just need to put a condition on that message so it only shows if the form has been sent. How do I do that Alien or anyone? Thanks

I see that you’re using $_SESSION but doesn’t appear to have resumed the session beforehand.

Thank you for the answer, so is this the idea?

$lastpage = $_SERVER['HTTP_REFERER']; 

if (($_SESSION['6_letters_code'] == $_POST['6_letters_code']) && !empty($_SESSION['6_letters_code'])) {
    $error = FALSE;    

Yes, that’s the idea.

Thanks Paul I’ll give it a try

session_start($_SESSION); <– remove $_SESSION from here.
reading documentation entry for the function before it use is great help