Testing if two fields have data in them

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2006
Ian Davies
 
Posts: n/a
Default Testing if two fields have data in them

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


Reply With Quote
  #2 (permalink)  
Old 04-20-2006
Gordon Burditt
 
Posts: n/a
Default Re: Testing if two fields have data in them

>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
Reply With Quote
  #3 (permalink)  
Old 04-20-2006
David Haynes
 
Posts: n/a
Default Re: Testing if two fields have data in them

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-

Reply With Quote
  #4 (permalink)  
Old 04-20-2006
Ian Davies
 
Posts: n/a
Default Re: Testing if two fields have data in them

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



Reply With Quote
  #5 (permalink)  
Old 04-20-2006
Ian Davies
 
Posts: n/a
Default Re: Testing if two fields have data in them

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-
>



Reply With Quote
  #6 (permalink)  
Old 04-20-2006
Geoff Berrow
 
Posts: n/a
Default Re: Testing if two fields have data in them

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/
Reply With Quote
  #7 (permalink)  
Old 04-20-2006
Jerry Stuckle
 
Posts: n/a
Default Re: Testing if two fields have data in them

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
==================
Reply With Quote
  #8 (permalink)  
Old 04-20-2006
Ian Davies
 
Posts: n/a
Default Re: Testing if two fields have data in them

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
> ==================



Reply With Quote
  #9 (permalink)  
Old 04-20-2006
Geoff Berrow
 
Posts: n/a
Default Re: Testing if two fields have data in them

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/
Reply With Quote
  #10 (permalink)  
Old 04-20-2006
fletch
 
Posts: n/a
Default Re: Testing if two fields have data in them

stick a print_r($_POST);die(); in where you have STUFF and send us the
output.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:22 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0