473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

help with form field validation

hello,

i am trying to validate a form field ... requiring the user to enter 1
of 2 possible security codes (for example 1000 or 9975).

this part of my code does not seem to working - it gives the error
message when I enter the correct security code(s).

if ($_POST['security_question'] != 1000 || 9975) {
$errors[]= 'You have entered an incorrect security code.';
}

any tips on handle this? i am somewhat new to php - any info is much
appreciated. thanks

May 29 '07 #1
4 1352
At Mon, 28 May 2007 18:22:11 -0700, hmlarson let h(is|er) monkeys type:
hello,

i am trying to validate a form field ... requiring the user to enter 1
of 2 possible security codes (for example 1000 or 9975).

this part of my code does not seem to working - it gives the error
message when I enter the correct security code(s).

if ($_POST['security_question'] != 1000 || 9975) {
$errors[]= 'You have entered an incorrect security code.';
}

any tips on handle this? i am somewhat new to php - any info is much
appreciated. thanks
Your code :

if ($_POST['security_question'] != 1000 || 9975)

should be something like:

if (($_POST['security_question'] != 1000) &&
($_POST['security_question'] != 1000)) {
[...]
}

It's easy to see this would become a lengthy script once there are more
valid answers. Imagine there are 10 valid codes, or 50...

So another way of doing it would be easier to maintain:

$valid_codes = array (1000,1248,1722,1769,9975,9999);
if (! in_array ($_POST['security_question'], $valid_codes)) {
// do 'invalid code stuff
}

Now adapting the script to accept other values as well is easy, just add
them to the $valid_codes array.

There are other ways still, as is often the case in programming. Ask 10
people and you might get 5 different solutions.

Good luck (with the homework ???? yes ???).
Rgds,

--
Schraalhans Keukenmeester - sc*********@the.spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') is -1"

May 29 '07 #2
At Tue, 29 May 2007 07:27:06 +0200, Schraalhans Keukenmeester let h(is|er)
monkeys type:
At Mon, 28 May 2007 18:22:11 -0700, hmlarson let h(is|er) monkeys type:
>hello,

i am trying to validate a form field ... requiring the user to enter 1
of 2 possible security codes (for example 1000 or 9975).

this part of my code does not seem to working - it gives the error
message when I enter the correct security code(s).

if ($_POST['security_question'] != 1000 || 9975) {
$errors[]= 'You have entered an incorrect security code.';
}

any tips on handle this? i am somewhat new to php - any info is much
appreciated. thanks

Your code :

if ($_POST['security_question'] != 1000 || 9975)

should be something like:

if (($_POST['security_question'] != 1000) &&
($_POST['security_question'] != 1000)) {
[...]
}
Oops, typo.

if (($_POST['security_question'] != 1000) &&
($_POST['security_question'] != 9975)) {
[...]
}

Sorry.

Sh.
May 29 '07 #3
On May 29, 6:22 am, hmlarson <hlar...@gmail.comwrote:
hello,

i am trying to validate a form field ... requiring the user to enter 1
of 2 possible security codes (for example 1000 or 9975).

this part of my code does not seem to working - it gives the error
message when I enter the correct security code(s).

if ($_POST['security_question'] != 1000 || 9975) {
$errors[]= 'You have entered an incorrect security code.';

}

any tips on handle this? i am somewhat new to php - any info is much
appreciated. thanks
u can also use mysql db for validating security codes if u hv many. if
u want its code, then tell me.

May 29 '07 #4
Thanks!!!

May 29 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Adrienne | last post by:
I am the first to admit that I know bupkis about javascript, except that sometimes I need it to do something client side that I can't do server side. Anyway, here's my problem: <input...
2
by: qsweetbee | last post by:
I have a form(fAddUsers) in my database. It is continue form for data entry. Some fields are required fields. Some are optional fields. There is 1 particular filed(TokenExpirationDate)on the form...
3
by: Earthling | last post by:
Any help would be appreciated to solve the following simple problem that I will describe. *** There is a form called "red chocolate form". The form has a particular subform field that has a...
37
by: Tim Marshall | last post by:
From http://www.mvps.org/access/tencommandments.htm 9th item: Thou shalt not use "SendKeys", "Smart Codes" or "GoTo" (unless the GoTo be part of an OnError process) for these will lead you...
5
by: Don Sealer | last post by:
I've got a validation rule that says something like =xx or xxx or zzzz. Though I may not have described it well it does work fine and that is really not my question. Here's what I'd like to do....
14
by: JNariss | last post by:
Hello, I am fairly new to asp and jscript and am now in the process of learning some form validation. I am taking one step at a time by validating each field and testing it before moving onto...
36
by: aljamala | last post by:
Hi, I keep getting this warning on a page, but I do not know what the problem is...does anyone have an idea about what could be wrong? line 88 column 7 - Warning: missing </formbefore <td> it...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
1
by: lilbit02 | last post by:
Hi, I have a form that utilizes validation as most do via javascript. This form worked totaly fine until I needed to add a dynamic div now the validation doesn't work. It does work for the first...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.