Not sure why this script is not working?

Posted on 16th Feb 2014 by admin

Hi I am new to php programing and I was trying to make up a simple script like a captcha but I cannot get the validation part of it working. I think it should work but it is not. Anyone know what is wrong. Any help is greatly appreciated. Here is the code:
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Captcha</title>
</head>
<body>

<?php

$alpha = 'abcdefghijklmnopqrstuvwxyz' ;
$shuffle = str_shuffle($alpha) ;
$partial = substr($shuffle , 0 , 4) ;
echo "$partial <br /><br />" ;

if (isset($_POST['submitted'])) {

//Valdate the info
if ($_POST['input'] != $partial) {
echo "Your answer does not match the capthcha. Please try again.<br /><br />" ;
} else {
echo "You answered correctly!<br /><br />" ;
}
}

?>

<form action="capthcha2.php" method="post">
<p>Enter Captcha: <input name="input" type="text" size="20" /></p>
<input name="submit" type="submit" value="Submit" />
<input name="submitted" type="hidden" value="true" />
</form>


</body>
</html>

Other forums