So I created my own PHP CAPTCHA, this is my method of creating it:
I have a table in my database named 'Captchas' and in that table, I have two categories: ID and Captcha.
On the Captcha page this is how I set it up:
$record = mysql_query("SELECT * FROM captchas ORDER BY rand() LIMIT 1");
while($row=mysql_fetch_array($record)){
$captcha = $row['captcha'];
echo $captcha;
}
Then I have a form with two inputs, text and submit
I have the following code for the form:
echo "<form method='POST'>";
if(isset($_POST['submit'])){
$input_captcha = $_POST['input_captcha'];
if($input_captcha == $captcha){
echo "<p>Correct Captcha.</p>";
} else {
echo "<p>Incorrect Captcha.</p>";
}
}
echo "<input type='text' name='input_captcha'/>";
echo "<input type='submit' name='submit'/>";
echo "</form>";
}
What this code does is checks if the user's input is equal to the captcha so it echos 'correct captcha' and if not, 'incorrect catpcha'. Though, the problem is that it checks if the inputted text is equal to the NEXT captcha number in the randomized array. I have no idea why this is happening?