theuserkaps
theuserkaps

Reputation: 308

my code is doing the opposite

my code is doing the opposite of what i want it to do,im trying to create a simple captcha when i enter the values or letters on the captcha and the username/name if the captcha letters are correct i want it to print hi $name,you types the correct captcha and if the data entered is wrong i just want it to print nooo.my problem is that when i enter the correct letters or data its printing noo and when i just leave it blank without entering any data its printing hi $name,you types the correct captcha

this my simple code

<?php
session_start();
?>
<html>
<head>
<title> captcha test</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){

if (isset($_SESSION['real'])) {
    $real = $_SESSION['real'];
}
$guess = $_POST['captcha'];
$name = $_POST['name'];
$real = "";
if ($real == $guess){

echo "hi $name,you types the correct name";
} 
else {

    echo "Nooo";
}

} else {
?>
<form action= 'index.php' method='post'>
your name:<input type = 'text' name='name' />
<br />
<img src= 'image.php'>  <input type='text' name='captcha' />
<br/>

<input type= 'submit' name='submit' value='go' />
</form>
<?php } ?>
</body>
</html>

what am i doing wrong?

Upvotes: 0

Views: 101

Answers (2)

David Harris
David Harris

Reputation: 2707

You are assigning a blank value to variable $real after you assigned a real value to it before.

$real = "";

Upvotes: 6

Sivagopal Manpragada
Sivagopal Manpragada

Reputation: 1634

you are making $real="" before the if condition check

Upvotes: 1

Related Questions