PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Check if any fields are filled in
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Check if any fields are filled in

Réponse
 
LinkBack Outils de la discussion
Vieux 06/11/2007, 15h50   #1
mtuller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.

  Réponse avec citation
Vieux 06/11/2007, 16h15   #2
Darko
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

On Nov 6, 4:50 pm, mtuller <mitul...@gmail.com> 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 ||

  Réponse avec citation
Vieux 06/11/2007, 16h32   #3
james@jgoode.co.uk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

On Nov 6, 4:15 pm, Darko <darko.maksimo...@gmail.com> wrote:
> On Nov 6, 4:50 pm, mtuller <mitul...@gmail.com> 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.

  Réponse avec citation
Vieux 06/11/2007, 16h56   #4
mtuller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

On Nov 6, 10:15 am, Darko <darko.maksimo...@gmail.com> wrote:
> On Nov 6, 4:50 pm, mtuller <mitul...@gmail.com> 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
&&.

  Réponse avec citation
Vieux 06/11/2007, 17h20   #5
Justin Koivisto
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

mtuller wrote:
> On Nov 6, 10:15 am, Darko <darko.maksimo...@gmail.com> wrote:
>> On Nov 6, 4:50 pm, mtuller <mitul...@gmail.com> 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

  Réponse avec citation
Vieux 06/11/2007, 17h38   #6
mtuller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

On Nov 6, 11:20 am, Justin Koivisto <justin.koivi...@gmail.com> wrote:
> mtuller wrote:
> > On Nov 6, 10:15 am, Darko <darko.maksimo...@gmail.com> wrote:
> >> On Nov 6, 4:50 pm, mtuller <mitul...@gmail.com> 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.

  Réponse avec citation
Vieux 06/11/2007, 17h41   #7
Good Man
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

mtuller <mituller@gmail.com> wrote in
news:1194370693.692490.11330@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.
  Réponse avec citation
Vieux 06/11/2007, 18h00   #8
mtuller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

On Nov 6, 11:41 am, Good Man <he...@letsgo.com> wrote:
> mtuller <mitul...@gmail.com> wrote innews:1194370693.692490.11330@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.

  Réponse avec citation
Vieux 06/11/2007, 18h12   #9
Good Man
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

mtuller <mituller@gmail.com> wrote in
news:1194372034.748781.192620@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!!!


  Réponse avec citation
Vieux 06/11/2007, 18h19   #10
mtuller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

On Nov 6, 12:12 pm, Good Man <he...@letsgo.com> wrote:
> mtuller <mitul...@gmail.com> wrote innews:1194372034.748781.192620@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?!

  Réponse avec citation
Vieux 06/11/2007, 18h38   #11
Lars Eighner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

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 <he...@letsgo.com> wrote:
>> mtuller <mitul...@gmail.com> wrote innews:1194370693.692490.11330@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?
  Réponse avec citation
Vieux 06/11/2007, 19h14   #12
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

..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:1194365743.911855.266720@50g2000hsm.googlegr oups.com>

Micha
  Réponse avec citation
Vieux 06/11/2007, 21h20   #13
mtuller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

On Nov 6, 1:14 pm, Michael Fesser <neti...@gmx.de> 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:
>
> <news:1194365743.911855.266720@50g2000hsm.googlegr oups.com>
>
> Micha


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

  Réponse avec citation
Vieux 06/11/2007, 21h26   #14
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

..oO(mtuller)

>On Nov 6, 1:14 pm, Michael Fesser <neti...@gmx.de> wrote:
>>
>> The solution was already posted:
>>
>> <news:1194365743.911855.266720@50g2000hsm.googlegr oups.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
  Réponse avec citation
Vieux 06/11/2007, 21h28   #15
Good Man
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

mtuller <mituller@gmail.com> wrote in news:1194384049.997043.5250@
19g2000hsx.googlegroups.com:

> On Nov 6, 1:14 pm, Michael Fesser <neti...@gmx.de> 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:
>>
>> <news:1194365743.911855.266720@50g2000hsm.googlegr oups.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.";
}


  Réponse avec citation
Vieux 06/11/2007, 22h58   #16
Chuck Anderson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

Michael Fesser wrote:
> .oO(mtuller)
>
>
>> On Nov 6, 1:14 pm, Michael Fesser <neti...@gmx.de> wrote:
>>
>>> The solution was already posted:
>>>
>>> <news:1194365743.911855.266720@50g2000hsm.googlegr oups.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.
***********************************

  Réponse avec citation
Vieux 07/11/2007, 09h31   #17
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Check if any fields are filled in

..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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h56.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 1,11180 seconds with 25 queries