This is a discussion on Testing if two fields have data in them within the PHP Language forums, part of the PHP Programming Forums category; Im trying to test if two fields have been entered at the same time I have tried many combinations but ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Im trying to test if two fields have been entered at the same time
I have tried many combinations but cant get it. My last effort was if(isset($_POST['Link'] && isset($_POST['uploadedfile'])){ die('You can\'t select to upload a link and a file at the same time.'); } else { STUFF HERE; } but still cant get it to work Help appreciated Ian |
|
|||
|
>Im trying to test if two fields have been entered at the same time
>I have tried many combinations but cant get it. My last effort was > > >if(isset($_POST['Link'] && isset($_POST['uploadedfile'])){ >die('You can\'t select to upload a link and a file at the same time.'); >} >else >{ >STUFF HERE; >} > >but still cant get it to work > >Help appreciated So what happens when you try? It gives you the error when it shouldn't, or it doesn't give you the error when it should? A blank field is not the same as NO field. I'm going to guess that you mean: if ((isset($_POST['Link']) && $_POST['Link'] != '') && (isset($_POST['uploadedfile']) && $_POST['uploadedfile'] != '') { Gordon L. Burditt |
|
|||
|
Ian Davies wrote:
> Im trying to test if two fields have been entered at the same time > I have tried many combinations but cant get it. My last effort was > > > if(isset($_POST['Link'] && isset($_POST['uploadedfile'])){ > die('You can\'t select to upload a link and a file at the same time.'); > } > else > { > STUFF HERE; > } > > but still cant get it to work > > Help appreciated > > Ian > > Watch the scope of the isset. I think you wanted: if( isset($_POST['Link']) && isset($_POST['uploadedfile']) ) { -david- |
|
|||
|
Thanks Gordon
Unfortunately your solution does not work. It allows the 'else' part of the code to proceed Ian "Gordon Burditt" <gordonb.lkgz9@burditt.org> wrote in message news:124df97s3t7rr2a@corp.supernews.com... > >Im trying to test if two fields have been entered at the same time > >I have tried many combinations but cant get it. My last effort was > > > > > >if(isset($_POST['Link'] && isset($_POST['uploadedfile'])){ > >die('You can\'t select to upload a link and a file at the same time.'); > >} > >else > >{ > >STUFF HERE; > >} > > > >but still cant get it to work > > > >Help appreciated > > So what happens when you try? It gives you the error when it shouldn't, > or it doesn't give you the error when it should? > > A blank field is not the same as NO field. I'm going to guess > that you mean: > > if ((isset($_POST['Link']) && $_POST['Link'] != '') > && (isset($_POST['uploadedfile']) && $_POST['uploadedfile'] != '') { > > Gordon L. Burditt |
|
|||
|
Thanks Dave
But I tried that and that isnt it either It also allows the 'else' part of the code to proceed Ian "David Haynes" <david.haynes2@sympatico.ca> wrote in message news:Fzz1g.98964$bk2.19359@fe72.usenetserver.com.. . > Ian Davies wrote: > > Im trying to test if two fields have been entered at the same time > > I have tried many combinations but cant get it. My last effort was > > > > > > if(isset($_POST['Link'] && isset($_POST['uploadedfile'])){ > > die('You can\'t select to upload a link and a file at the same time.'); > > } > > else > > { > > STUFF HERE; > > } > > > > but still cant get it to work > > > > Help appreciated > > > > Ian > > > > > > Watch the scope of the isset. I think you wanted: > if( isset($_POST['Link']) && isset($_POST['uploadedfile']) ) { > > -david- > |
|
|||
|
Message-ID: <SQy1g.55760$Nh7.17628@newsfe4-win.ntli.net> from Ian Davies
contained the following: >if(isset($_POST['Link'] && isset($_POST['uploadedfile'])){ isset will return true for certain form elements even if they are empty. Assuming the elements are not checkboxes radio boxes or buttons, try if(!empty($_POST['Link']) && !empty($_POST['uploadedfile'])){ .... If this doesn't work, let us know what elements you are dealing with. -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies. My opinions, not the committee's, mine. Simple RFDs http://www.ckdog.co.uk/rfdmaker/ |
|
|||
|
Ian Davies wrote:
> Thanks Gordon > Unfortunately your solution does not work. It allows the 'else' part of the > code to proceed > > Ian > > "Gordon Burditt" <gordonb.lkgz9@burditt.org> wrote in message > news:124df97s3t7rr2a@corp.supernews.com... > >>>Im trying to test if two fields have been entered at the same time >>>I have tried many combinations but cant get it. My last effort was >>> >>> >>>if(isset($_POST['Link'] && isset($_POST['uploadedfile'])){ >>>die('You can\'t select to upload a link and a file at the same time.'); >>>} >>>else >>>{ >>>STUFF HERE; >>>} >>> >>>but still cant get it to work >>> >>>Help appreciated >> >>So what happens when you try? It gives you the error when it shouldn't, >>or it doesn't give you the error when it should? >> >>A blank field is not the same as NO field. I'm going to guess >>that you mean: >> >>if ((isset($_POST['Link']) && $_POST['Link'] != '') >> && (isset($_POST['uploadedfile']) && $_POST['uploadedfile'] != '') { >> >>Gordon L. Burditt > > > But if the condition is false, the else clause SHOULD run. What's the problem? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Hi
The problem is that the alternative runs even when it shouldnt. The code should be such that if the the two fields have something in them then an error should be produced. Let me expand on what Im trying to do I wish the users to either to upload a file to my website or as an alternative send a link to their website which is added to a table in my database. The first option the user browses for their file and it is submitted via type=file The second option uses type=text What I wish to do is to stop user from putting data into both fields I want the code to test the submitted data and if text field and file field have something in them then a message would say 'You cant submit a link and a file at the same time' To see what Im trying to acheive go to http://www.iddsoftware.co.uk/Resources.php Thanks Ian "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message news:J6ydnenpLZgrY9vZRVn-ug@comcast.com... > Ian Davies wrote: > > Thanks Gordon > > Unfortunately your solution does not work. It allows the 'else' part of the > > code to proceed > > > > Ian > > > > "Gordon Burditt" <gordonb.lkgz9@burditt.org> wrote in message > > news:124df97s3t7rr2a@corp.supernews.com... > > > >>>Im trying to test if two fields have been entered at the same time > >>>I have tried many combinations but cant get it. My last effort was > >>> > >>> > >>>if(isset($_POST['Link'] && isset($_POST['uploadedfile'])){ > >>>die('You can\'t select to upload a link and a file at the same time.'); > >>>} > >>>else > >>>{ > >>>STUFF HERE; > >>>} > >>> > >>>but still cant get it to work > >>> > >>>Help appreciated > >> > >>So what happens when you try? It gives you the error when it shouldn't, > >>or it doesn't give you the error when it should? > >> > >>A blank field is not the same as NO field. I'm going to guess > >>that you mean: > >> > >>if ((isset($_POST['Link']) && $_POST['Link'] != '') > >> && (isset($_POST['uploadedfile']) && $_POST['uploadedfile'] != '') { > >> > >>Gordon L. Burditt > > > > > > > > > But if the condition is false, the else clause SHOULD run. What's the problem? > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstucklex@attglobal.net > ================== |
|
|||
|
Message-ID: <FTH1g.36888$zf1.12352@newsfe5-gui.ntli.net> from Ian Davies
contained the following: >The first option the user browses for their file and it is submitted via >type=file Ah... if(!empty($_POST['Link']) && !empty($_FILES['uploadedfile'])){ .... -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies. My opinions, not the committee's, mine. Simple RFDs http://www.ckdog.co.uk/rfdmaker/ |