Jump to content

Recommended Posts

I am currently working on an account signup script and have a form field called "math" that works as a simple Captcha and asks the following question:

 

Anti-Spam Question: 1 - 1 = ?

 

Of course as we know the answer is zero/0

 

However, in my php script when I run this code it will return as empty when someone enters the number "0" rather then typing "zero", or "Zero", or "ZERO", but returns true if they enter any of the last three options.

 

<?php
// validate math function and check for empty fields
if ($math != "0" && $math != "zero" && $math != "Zero" && $math != "ZERO") {
   echo "You Did Not Answer the Math Problem Correctly";
  exit ;
}
if (empty($math)) {
   echo "Please Complete All Form Fields";
  exit ;
}
?>

 

My question is how come it won't recognize the number 0 and is there a way to prevent this from happening?

 

Any help would be appreciated.

 

Thanks,

 

kaiman

Link to comment
https://forums.phpfreaks.com/topic/180715-solved-form-field-validation-question/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.