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

Home Posts Topics Members FAQ

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
Apr 19 '06 #1
13 1446
>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
Apr 19 '06 #2
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-

Apr 19 '06 #3
Thanks Gordon
Unfortunately your solution does not work. It allows the 'else' part of the
code to proceed

Ian

"Gordon Burditt" <go***********@burditt.org> wrote in message
news:12*************@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

Apr 20 '06 #4
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" <da***********@sympatico.ca> wrote in message
news:Fz*******************@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-

Apr 20 '06 #5
Message-ID: <SQ*******************@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/
Apr 20 '06 #6
Ian Davies wrote:
Thanks Gordon
Unfortunately your solution does not work. It allows the 'else' part of the
code to proceed

Ian

"Gordon Burditt" <go***********@burditt.org> wrote in message
news:12*************@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.
js*******@attglobal.net
==================
Apr 20 '06 #7
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" <js*******@attglobal.net> wrote in message
news:J6********************@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" <go***********@burditt.org> wrote in message
news:12*************@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.
js*******@attglobal.net
==================

Apr 20 '06 #8
stick a print_r($_POST);die(); in where you have STUFF and send us the
output.

Apr 20 '06 #9
Message-ID: <FT*******************@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/
Apr 20 '06 #10
Rik
Geoff Berrow wrote:
Message-ID: <SQ*******************@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.


A simple print_r($_POST) would clarify a lot....
Enough working examples in this thread.

If the current examples don't work, $_POST['uploadedfile'] makes me suspect
the $_FILES array should by checked....

Grtz,
--
Rik Wasmus
Apr 20 '06 #11
Cheers Geoff
That was it

Ian

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:7o********************************@4ax.com...
Message-ID: <FT*******************@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/

Apr 20 '06 #12
Rik
Rik wrote:
If the current examples don't work, $_POST['uploadedfile'] makes me
suspect the $_FILES array should by checked....


D'ok, that answer was already giiven.
Refreshing the ng after browsing for a while can save a lot of time :-)

Grtz,
--
Rik
Apr 20 '06 #13
Ian Davies wrote:
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" <js*******@attglobal.net> wrote in message
news:J6********************@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" <go***********@burditt.org> wrote in message
news:12*************@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.
js*******@attglobal.net
==================



Personally, I would have just put the two fields in two different forms, each
with its own submit button. Both can be submitted to the same page; just give
the buttons different names.

It's also more obvious that you're looking for one OR the other.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 20 '06 #14

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

Similar topics

4
by: Hugh Cowan | last post by:
Hello, I don't program full-time (anymore), but I do try and stay on-top of the latest technologies and like most are always trying to upgrade my skills and remain current (as much as is...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
2
by: Tilted | last post by:
Evening chaps I'm after a bit of advice, I've written a data tier using attributes, reflection and inheritance, to test it I've written a simple order entry program. Glad I did as it picked up...
39
by: windandwaves | last post by:
Hi Folk I have to store up to eight boolean bits of information about an item in my database. e.g. with restaurant drive-through facility yellow windows
6
by: Dick | last post by:
I’d appreciate some advice regarding unit tests. My questions are general in nature but (as usual) best conveyed via a (simplified) example: I have a table that contains two columns – the...
1
by: Dave | last post by:
I have multiple forms that will create an object. Basically a energy efficiency measure object. The measure object will have a couple of required properties set but after that it can have 10-20...
0
by: Matthew Fitzgibbons | last post by:
I'm by no means a testing expert, but I'll take a crack at it. Casey McGinty wrote: I've never run into this. Rule of thumb: always separate software from hardware. Write mock classes or...
3
by: ibeehbk | last post by:
Hi. I have a form made in xhtml. I test via vbscript to make sure none of the fields are empty and properly formatted (ie email). All the regular fields work. However, I have two drop down menus...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.