Check if any fields are filled in
Check if any fields are filled in
am 06.11.2007 16:50:35 von mtuller
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.
Re: Check if any fields are filled in
am 06.11.2007 17:15:43 von darko
On Nov 6, 4:50 pm, mtuller wrote:
> 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 ||
Re: Check if any fields are filled in
am 06.11.2007 17:32:08 von James
On Nov 6, 4:15 pm, Darko wrote:
> On Nov 6, 4:50 pm, mtuller wrote:
>
> > 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.
Re: Check if any fields are filled in
am 06.11.2007 17:56:33 von mtuller
On Nov 6, 10:15 am, Darko wrote:
> On Nov 6, 4:50 pm, mtuller wrote:
>
> > 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
&&.
Re: Check if any fields are filled in
am 06.11.2007 18:20:56 von Justin Koivisto
mtuller wrote:
> On Nov 6, 10:15 am, Darko wrote:
>> On Nov 6, 4:50 pm, mtuller wrote:
>>
>>> 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
Re: Check if any fields are filled in
am 06.11.2007 18:38:13 von mtuller
On Nov 6, 11:20 am, Justin Koivisto wrote:
> mtuller wrote:
> > On Nov 6, 10:15 am, Darko wrote:
> >> On Nov 6, 4:50 pm, mtuller wrote:
>
> >>> 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.
Re: Check if any fields are filled in
am 06.11.2007 18:41:34 von Good Man
mtuller wrote in
news:1194370693.692490.11330@19g2000hsx.googlegroups.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.
Re: Check if any fields are filled in
am 06.11.2007 19:00:34 von mtuller
On Nov 6, 11:41 am, Good Man wrote:
> mtuller wrote innews:1194370693.692490.11330@19g2000hsx.googlegroups.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.
Re: Check if any fields are filled in
am 06.11.2007 19:12:26 von Good Man
mtuller wrote in
news:1194372034.748781.192620@o38g2000hse.googlegroups.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!!!
Re: Check if any fields are filled in
am 06.11.2007 19:19:33 von mtuller
On Nov 6, 12:12 pm, Good Man wrote:
> mtuller wrote innews:1194372034.748781.192620@o38g2000hse.googlegroups.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?!
Re: Check if any fields are filled in
am 06.11.2007 19:38:20 von Lars Eighner
In our last episode,
<1194372034.748781.192620@o38g2000hse.googlegroups.com>, the lovely and
talented mtuller broadcast on comp.lang.php:
> On Nov 6, 11:41 am, Good Man wrote:
>> mtuller wrote innews:1194370693.692490.11330@19g2000hsx.googlegroups.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
Countdown: 440 days to go.
What do you do when you're debranded?
Re: Check if any fields are filled in
am 06.11.2007 20:14:54 von Michael Fesser
..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:
Micha
Re: Check if any fields are filled in
am 06.11.2007 22:20:49 von mtuller
On Nov 6, 1:14 pm, Michael Fesser wrote:
> .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:
>
>
>
> Micha
Just my luck today. The link you gave me says it can't be found.
Re: Check if any fields are filled in
am 06.11.2007 22:26:09 von Michael Fesser
..oO(mtuller)
>On Nov 6, 1:14 pm, Michael Fesser wrote:
>>
>> The solution was already posted:
>>
>>
>
>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
Re: Check if any fields are filled in
am 06.11.2007 22:28:10 von Good Man
mtuller wrote in news:1194384049.997043.5250@
19g2000hsx.googlegroups.com:
> On Nov 6, 1:14 pm, Michael Fesser wrote:
>> .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:
>>
>>
>>
>> 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.";
}
Re: Check if any fields are filled in
am 06.11.2007 23:58:24 von Chuck Anderson
Michael Fesser wrote:
> .oO(mtuller)
>
>
>> On Nov 6, 1:14 pm, Michael Fesser wrote:
>>
>>> The solution was already posted:
>>>
>>>
>>>
>> 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.
***********************************
Re: Check if any fields are filled in
am 07.11.2007 10:31:38 von Michael Fesser
..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