how to validate a captcha on my registration page
<p>i am trying to put a simple captcha on registration page but i am getting failing to validate the captcha part on my form
if i leave the username part on the form blank and press register it will give me a message please enter username and so on but when it comes to the captcha part if i leave it blank it will give a message enter captcha but if i enter the captcha letter but not the correct one it registers,so i want to try and combine this code below</p>

<pre><code>if ( $real == $guess ) {
    die ("enter captcha");
} 
</code></pre>

<p>and this code</p>

<pre><code>if ( $real != $guess ) {
   die ("Not equal");
} 
</code></pre>

<p>this is my register page code</p>

<pre><code>//Collecting info
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$pass_conf = $_REQUEST['password_conf'];
$email = $_REQUEST['email'];
$date = $_REQUEST['date'];
$guess = $_POST['captcha'];

$real = ( isset( $_SESSION['real'] ) ) ? $_SESSION['real'] : "";

//Here we will check do we have all inputs filled

if ( empty( $username ) ) {
    die("Please enter your username!&lt;br&gt;");
}

if ( empty( $password ) ) {
    die("Please enter your password!&lt;br&gt;");
}

if ( empty( $pass_conf ) ) {
   die("Please confirm your password!&lt;br&gt;");
}

if ( empty( $email ) ) {
   die("Please enter your email!");
}
if ( $real == $guess ) {
   die ("enter captcha");
} 

//Let's check if this username is already in use

$user_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$do_user_check = mysql_num_rows( $user_check );

//Now if email is already in use

$email_check = mysql_query("SELECT email FROM users WHERE email='$email'");
$do_email_check = mysql_num_rows( $email_check );

//Now display errors

if ( $do_user_check &gt; 0 ) {
    die("Username is already in use!&lt;br&gt;");
}

if ( $do_email_check &gt; 0 ) {
    die("Email is already in use!");
}

//Now let's check does passwords match

if( $password != $pass_conf ) {
   die("Passwords don't match!");
}

//If everything is okay let's register this user

$insert = mysql_query("INSERT INTO users (username, password, email) VALUES ('$username', '$password', '$email')");
if ( !$insert ) {
   die("There's little problem: ".mysql_error());
}

echo $username.", you are now registered. Thank you!&lt;br&gt;&lt;a href=login.php&gt;Login&lt;/a&gt; | &lt;a href=index.php&gt;Index&lt;/a&gt;";

}
$act = isset($_GET['act']) ? $_GET['act'] : '';
switch( $act ) {
   default;
   register_form();
   break;

   case "register";
   register();
   break;
}
</code></pre>
