473,490 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Check if any fields are filled in

I am creating a page for nomination and want to let the information
pass if any field are filled out, but if none are filled out, a
message will appear. I can't get the check to happen on multiple
fields though.

Here is what I have:
if ($nominee_first_name !=='' && $nominee_middle_initial !=='' &&
$nominee_last_name !=='')

What happens is that if all fields have content, the page passes, and
all I care about is that there is something entered in at least one
field.

Nov 6 '07 #1
16 4138
On Nov 6, 4:50 pm, mtuller <mitul...@gmail.comwrote:
I am creating a page for nomination and want to let the information
pass if any field are filled out, but if none are filled out, a
message will appear. I can't get the check to happen on multiple
fields though.

Here is what I have:
if ($nominee_first_name !=='' && $nominee_middle_initial !=='' &&
$nominee_last_name !=='')

What happens is that if all fields have content, the page passes, and
all I care about is that there is something entered in at least one
field.
Replace && with ||

Nov 6 '07 #2
On Nov 6, 4:15 pm, Darko <darko.maksimo...@gmail.comwrote:
On Nov 6, 4:50 pm, mtuller <mitul...@gmail.comwrote:
I am creating a page for nomination and want to let the information
pass if any field are filled out, but if none are filled out, a
message will appear. I can't get the check to happen on multiple
fields though.
Here is what I have:
if ($nominee_first_name !=='' && $nominee_middle_initial !=='' &&
$nominee_last_name !=='')
What happens is that if all fields have content, the page passes, and
all I care about is that there is something entered in at least one
field.

Replace && with ||
Just expanding on Darko's answer - && means 'if condition 1 and
condition 2 are true'. || means 'if at least one condition is true'.
Both can be used with more than two conditions as well.

Nov 6 '07 #3
On Nov 6, 10:15 am, Darko <darko.maksimo...@gmail.comwrote:
On Nov 6, 4:50 pm, mtuller <mitul...@gmail.comwrote:
I am creating a page for nomination and want to let the information
pass if any field are filled out, but if none are filled out, a
message will appear. I can't get the check to happen on multiple
fields though.
Here is what I have:
if ($nominee_first_name !=='' && $nominee_middle_initial !=='' &&
$nominee_last_name !=='')
What happens is that if all fields have content, the page passes, and
all I care about is that there is something entered in at least one
field.

Replace && with ||
Sorry, the subject of this is wrong. I don't want to check if any
fields are empty. I want to check if all are empty. That's why I have
&&.

Nov 6 '07 #4
mtuller wrote:
On Nov 6, 10:15 am, Darko <darko.maksimo...@gmail.comwrote:
>On Nov 6, 4:50 pm, mtuller <mitul...@gmail.comwrote:
>>I am creating a page for nomination and want to let the information
pass if any field are filled out, but if none are filled out, a
message will appear. I can't get the check to happen on multiple
fields though.
Here is what I have:
if ($nominee_first_name !=='' && $nominee_middle_initial !=='' &&
$nominee_last_name !=='')
What happens is that if all fields have content, the page passes, and
all I care about is that there is something entered in at least one
field.
Replace && with ||

Sorry, the subject of this is wrong. I don't want to check if any
fields are empty. I want to check if all are empty. That's why I have
&&.
if (empty($nominee_first_name) && empty($nominee_middle_initial) &&
empty($nominee_last_name))

--
Posted via a free Usenet account from http://www.teranews.com

Nov 6 '07 #5
On Nov 6, 11:20 am, Justin Koivisto <justin.koivi...@gmail.comwrote:
mtuller wrote:
On Nov 6, 10:15 am, Darko <darko.maksimo...@gmail.comwrote:
On Nov 6, 4:50 pm, mtuller <mitul...@gmail.comwrote:
>I am creating a page for nomination and want to let the information
pass if any field are filled out, but if none are filled out, a
message will appear. I can't get the check to happen on multiple
fields though.
Here is what I have:
if ($nominee_first_name !=='' && $nominee_middle_initial !=='' &&
$nominee_last_name !=='')
What happens is that if all fields have content, the page passes, and
all I care about is that there is something entered in at least one
field.
Replace && with ||
Sorry, the subject of this is wrong. I don't want to check if any
fields are empty. I want to check if all are empty. That's why I have
&&.

if (empty($nominee_first_name) && empty($nominee_middle_initial) &&
empty($nominee_last_name))

--
Posted via a free Usenet account fromhttp://www.teranews.com
I had tried that too. Except I used !empty.

if (!empty($nominee_first_name) && !empty($nominee_middle_initial) && !
empty($nominee_last_name))
{
// If not empty, insert into database
$nominee_field_query = "INSERT INTO faculty_nominations.nominations
(nominee_first_name, nominee_middle_initial, nominee_last_name,
nominee_comments)
values ('$nominee_first_name', '$nominee_middle_initial',
'$nominee_last_name', '$nominee_comments')";

// update database with infromation submitted
$db_query = mysqli_query ($db_connect, $nominee_field_query);

}
else
{
echo 'The fields are empty';
}

When I submit, if I have data in one field, but not in all, it
displays "The fields are empty". I want it to submit into the database
if any fileds are filled in, but not if there are no fields filled in.

Nov 6 '07 #6
mtuller <mi******@gmail.comwrote in
news:11*********************@19g2000hsx.googlegrou ps.com:

When I submit, if I have data in one field, but not in all, it
displays "The fields are empty". I want it to submit into the database
if any fileds are filled in, but not if there are no fields filled in.
but one post ago you said:

"Sorry, the subject of this is wrong. I don't want to check if any
fields are empty. I want to check if all are empty. That's why I have
&&."
So decide what exactly you are trying to do, and then pick either of the
solutions posted.
Nov 6 '07 #7
On Nov 6, 11:41 am, Good Man <he...@letsgo.comwrote:
mtuller <mitul...@gmail.comwrote innews:11*********************@19g2000hsx.googlegr oups.com:
When I submit, if I have data in one field, but not in all, it
displays "The fields are empty". I want it to submit into the database
if any fileds are filled in, but not if there are no fields filled in.

but one post ago you said:

"Sorry, the subject of this is wrong. I don't want to check if any
fields are empty. I want to check if all are empty. That's why I have
&&."

So decide what exactly you are trying to do, and then pick either of the
solutions posted.
Ok. I see where it sounds like I am saying different things, but I am
not. Let me try again...

I want to check to see if ALL fields are empty, and if they are, the
form is not submitted into the database. If any of the fields have
data though, I want it to be submitted. That is why I am checking with
&&. If $nominee_first_name AND $nominee_middle_initial AND
$nominee_last_name are all empty, echo "The fields are empty". If any
are filled in, then submit to the database.

Hope that explains better.

Nov 6 '07 #8
mtuller <mi******@gmail.comwrote in
news:11**********************@o38g2000hse.googlegr oups.com:

>So decide what exactly you are trying to do, and then pick either of
the solutions posted.

Ok. I see where it sounds like I am saying different things, but I am
not. Let me try again...

I want to check to see if ALL fields are empty, and if they are, the
form is not submitted into the database. If any of the fields have
data though, I want it to be submitted. That is why I am checking with
&&. If $nominee_first_name AND $nominee_middle_initial AND
$nominee_last_name are all empty, echo "The fields are empty". If any
are filled in, then submit to the database.

Hope that explains better.
perfect!

so you know what you want to do, does this mean you've chosen a solution
from the thread, or can create your own? you've said exactly what you want
to do above (even in code term, no less) so just put it together!!!
Nov 6 '07 #9
On Nov 6, 12:12 pm, Good Man <he...@letsgo.comwrote:
mtuller <mitul...@gmail.comwrote innews:11**********************@o38g2000hse.google groups.com:
So decide what exactly you are trying to do, and then pick either of
the solutions posted.
Ok. I see where it sounds like I am saying different things, but I am
not. Let me try again...
I want to check to see if ALL fields are empty, and if they are, the
form is not submitted into the database. If any of the fields have
data though, I want it to be submitted. That is why I am checking with
&&. If $nominee_first_name AND $nominee_middle_initial AND
$nominee_last_name are all empty, echo "The fields are empty". If any
are filled in, then submit to the database.
Hope that explains better.

perfect!

so you know what you want to do, does this mean you've chosen a solution
from the thread, or can create your own? you've said exactly what you want
to do above (even in code term, no less) so just put it together!!!
THEY DON'T WORK!!!! Do you think I am posting for my health?!

Nov 6 '07 #10
In our last episode,
<11**********************@o38g2000hse.googlegroups .com>, the lovely and
talented mtuller broadcast on comp.lang.php:
On Nov 6, 11:41 am, Good Man <he...@letsgo.comwrote:
>mtuller <mitul...@gmail.comwrote innews:11*********************@19g2000hsx.googlegr oups.com:
When I submit, if I have data in one field, but not in all, it
displays "The fields are empty". I want it to submit into the database
if any fileds are filled in, but not if there are no fields filled in.

but one post ago you said:

"Sorry, the subject of this is wrong. I don't want to check if any
fields are empty. I want to check if all are empty. That's why I have
&&."

So decide what exactly you are trying to do, and then pick either of the
solutions posted.
Ok. I see where it sounds like I am saying different things, but I am
not. Let me try again...
I want to check to see if ALL fields are empty, and if they are, the
form is not submitted into the database.
Good grief, don't they teach programmers any symbolic logic anymore?

All fields empty is the same as not(one of them is filled in).
If any of the fields have data though, I want it to be submitted. That is
why I am checking with &&.
But obviously that is wrong.
If $nominee_first_name AND $nominee_middle_initial AND $nominee_last_name
are all empty, echo "The fields are empty".
If $nominee_first_name AND $nominee_middle_initial AND
$nominee_last_name are all empty = If not($nominee_first_name is empty OR
$nominee_middle_initial is empty OR $nominee_last_name is empty)
If any are filled in, then submit to the database.
Hope that explains better.
--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 440 days to go.
What do you do when you're debranded?
Nov 6 '07 #11
..oO(mtuller)
>Ok. I see where it sounds like I am saying different things, but I am
not. Let me try again...

I want to check to see if ALL fields are empty, and if they are, the
form is not submitted into the database. If any of the fields have
data though, I want it to be submitted. That is why I am checking with
&&. If $nominee_first_name AND $nominee_middle_initial AND
$nominee_last_name are all empty, echo "The fields are empty". If any
are filled in, then submit to the database.

Hope that explains better.
The solution was already posted:

<news:11**********************@50g2000hsm.googlegr oups.com>

Micha
Nov 6 '07 #12
On Nov 6, 1:14 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(mtuller)
Ok. I see where it sounds like I am saying different things, but I am
not. Let me try again...
I want to check to see if ALL fields are empty, and if they are, the
form is not submitted into the database. If any of the fields have
data though, I want it to be submitted. That is why I am checking with
&&. If $nominee_first_name AND $nominee_middle_initial AND
$nominee_last_name are all empty, echo "The fields are empty". If any
are filled in, then submit to the database.
Hope that explains better.

The solution was already posted:

<news:11**********************@50g2000hsm.googlegr oups.com>

Micha
Just my luck today. The link you gave me says it can't be found.

Nov 6 '07 #13
..oO(mtuller)
>On Nov 6, 1:14 pm, Michael Fesser <neti...@gmx.dewrote:
>>
The solution was already posted:

<news:11**********************@50g2000hsm.googleg roups.com>

Just my luck today. The link you gave me says it can't be found.
It was the first reply in this thread from Darko:

| Replace && with ||

Micha
Nov 6 '07 #14
mtuller <mi******@gmail.comwrote in news:1194384049.997043.5250@
19g2000hsx.googlegroups.com:
On Nov 6, 1:14 pm, Michael Fesser <neti...@gmx.dewrote:
>.oO(mtuller)
>Ok. I see where it sounds like I am saying different things, but I
am
>not. Let me try again...
>I want to check to see if ALL fields are empty, and if they are, the
form is not submitted into the database. If any of the fields have
data though, I want it to be submitted. That is why I am checking
with
>&&. If $nominee_first_name AND $nominee_middle_initial AND
$nominee_last_name are all empty, echo "The fields are empty". If
any
>are filled in, then submit to the database.
>Hope that explains better.

The solution was already posted:

<news:11**********************@50g2000hsm.googleg roups.com>

Micha

Just my luck today. The link you gave me says it can't be found.
Only because it's sooooo very painful to watch you struggle... note that
you know exactly what you want, in fact up above you've specified it in
coding terms!!!!!!

if(($nominee_first_name=="") && ($nominee_middle_initial=="") &&
($nominee_last_name=="")) {
echo "The fields are empty.";
}
else {
enterTheDamnCode();
}

Notice how the clause is EXACTLY WHAT YOU WERE SAYING IN PLAIN ENGLISH
UP ABOVE!!!!!!
Now, to add a bit of insight as to why this got confusing for you - at
first you were checking for NOT empty:

if ($nominee_first_name !=='' && $nominee_middle_initial !=='' &&
$nominee_last_name !=='')

.... and in that case, you would use || ("or") and reverse the call:

if ($nominee_first_name !='' || $nominee_middle_initial !='' ||
$nominee_last_name !='') {
enterTheDamnCode();
}
else {
echo "The fields are empty.";
}
Nov 6 '07 #15
Michael Fesser wrote:
.oO(mtuller)

>On Nov 6, 1:14 pm, Michael Fesser <neti...@gmx.dewrote:
>>The solution was already posted:

<news:11**********************@50g2000hsm.google groups.com>
Just my luck today. The link you gave me says it can't be found.

It was the first reply in this thread from Darko:

| Replace && with ||

Micha
..... Just a note: I've switched to using AND and OR instead of && and
||. Seems a little clearer to me when I read the code.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Nothing he's got he really needs
Twenty first century schizoid man.
***********************************

Nov 6 '07 #16
..oO(Chuck Anderson)
>.... Just a note: I've switched to using AND and OR instead of && and
||. Seems a little clearer to me when I read the code.
No problem with that, just keep in mind that AND/OR have a lower
precedence than &&/||.

Micha
Nov 7 '07 #17

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

Similar topics

4
2161
by: Gleep | last post by:
Hi PHP coders, I've got an issue I'm stuck with. Imagine there is a large form that has 5 columns and 20 rows. In each row there is a check box - then 4 input fields. I already have the code...
3
3315
by: Matt Herson | last post by:
I am looking for a validation script that will only look at the fields in the cgi form, determine if the fields are filled out, then if one or more are blank will write a message at the top of the...
5
6299
by: Steve Wylie | last post by:
I am constructing an HTML questionnaire and one of the questions requires people to rate some choices from 1 to 5, where 1 is their favourite and 5 is their least favourite: Car Bus Taxi cab...
2
1572
by: Chris Windsor | last post by:
I hope the following describe what I'm trying to do: I have created a tool to be used by product analysts when studying different cell phone designs. Part of the tool is a set of 11 forms on a...
5
24594
by: Krechting | last post by:
Hi ALl, I have a code that checks if the documents in a hyperlink field are still where they should be. I use fileexist(). First I want to filter out all the hyperlink fields that are empty. I...
2
39066
by: bufbec1 | last post by:
I am pretty good with Access, but do not understand VBA. I have researched this topic and see only VBA answers, so I hope someone can help with my specific question. I have 2 fields for an...
1
2716
by: griemer | last post by:
I have a database like this id, field1,field2,field3,field4,field5 Database contains 100 rows, some rows have no fields filled, some 1field , some 2 fields etc. How would i count the...
14
1874
by: ankitmathur | last post by:
Hi, I'm facing a pretty peculiar problem. In one of my pages I print the number of rows depending upon the number of Qty I got filled in my previous page i.e. If Qty is filled in as 3 in...
4
2194
by: Samuel Murray | last post by:
G'day everyone I'm not a JavaScript programmer, so I wonder if you could point me in the right direction or simply tell me how to do the following. I'd like to submit a patch for the...
0
6967
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
7181
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...
1
6847
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
7352
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
5445
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,...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.