473,587 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

testing the condition of a pair of fields

Hi

Can anyone tell me why the following code will NOT work
The error message should be displayed when there is something in both fields

if ((isset($_POST['Link']) && $_POST['Link'] !=='') &&
(isset($_POST['uploadedfile']) && $_POST['uploadedfile'] !=='')) {
$error_msg.="<b r>You can't select to upload a link and a file at the same
time.";

curiously the following works

if(empty($_POST['Link']) || $_POST['Link'] ='' &&
empty($_FILES['uploadedfile']) || $_FILES['uploadedfile'] ='') {
$error_msg.="<b r>You didn't select whether to upload a link or a file.";
}

to display a message when there is nothing in both fields

help gratefuly requested
Ian
Jun 26 '06 #1
6 1382
Ian Davies wrote:
if ((isset($_POST['Link']) && $_POST['Link'] !=='') &&
(isset($_POST['uploadedfile']) && $_POST['uploadedfile'] !=='')) {
$error_msg.="<b r>You can't select to upload a link and a file at the
same time.";

This way, the condition only applies when both sub-conditions are true (both
fields are non-empty); replace the && between the sub-conditions with ||

if ((isset($v) && $v !=='') || (isset($v2) && $v2 !=='')) {
...
}
curiously the following works

if(empty($_POST['Link']) || $_POST['Link'] ='' &&
empty($_FILES['uploadedfile']) || $_FILES['uploadedfile'] ='') {
$error_msg.="<b r>You didn't select whether to upload a link or a
file."; }


That's because with the ||, only one test has to pass. Also note that you
are not compatring values (==) but assigning them (=).
JW

Jun 26 '06 #2
>This way, the condition only applies when both sub-conditions are true
(both
fields are non-empty);
Thats exactly what I want only one field should have something in it and
both fields should NOT be empty at the same time. But it doesnt work.

Ian
"Janwillem Borleffs" <jw@jwscripts.c om> wrote in message
news:44******** *************** @news.euronet.n l... Ian Davies wrote:
if ((isset($_POST['Link']) && $_POST['Link'] !=='') &&
(isset($_POST['uploadedfile']) && $_POST['uploadedfile'] !=='')) {
$error_msg.="<b r>You can't select to upload a link and a file at the
same time.";

This way, the condition only applies when both sub-conditions are true

(both fields are non-empty); replace the && between the sub-conditions with ||

if ((isset($v) && $v !=='') || (isset($v2) && $v2 !=='')) {
...
}
curiously the following works

if(empty($_POST['Link']) || $_POST['Link'] ='' &&
empty($_FILES['uploadedfile']) || $_FILES['uploadedfile'] ='') {
$error_msg.="<b r>You didn't select whether to upload a link or a
file."; }


That's because with the ||, only one test has to pass. Also note that you
are not compatring values (==) but assigning them (=).
JW

Jun 26 '06 #3
kay

Ian Davies написав:
This way, the condition only applies when both sub-conditions are true

(both
fields are non-empty);


Thats exactly what I want only one field should have something in it and
both fields should NOT be empty at the same time. But it doesnt work.

Ian
"Janwillem Borleffs" <jw@jwscripts.c om> wrote in message
news:44******** *************** @news.euronet.n l...
Ian Davies wrote:
if ((isset($_POST['Link']) && $_POST['Link'] !=='') &&
(isset($_POST['uploadedfile']) && $_POST['uploadedfile'] !=='')) {
$error_msg.="<b r>You can't select to upload a link and a file at the
same time.";


This way, the condition only applies when both sub-conditions are true

(both
fields are non-empty); replace the && between the sub-conditions with ||

if ((isset($v) && $v !=='') || (isset($v2) && $v2 !=='')) {
...
}
curiously the following works

if(empty($_POST['Link']) || $_POST['Link'] ='' &&
empty($_FILES['uploadedfile']) || $_FILES['uploadedfile'] ='') {
$error_msg.="<b r>You didn't select whether to upload a link or a
file."; }


That's because with the ||, only one test has to pass. Also note that you
are not compatring values (==) but assigning them (=).
JW


The boolean result of initialization the variables in 'if' condition
is always 'true' so the code like

if ( (...||...||...| |$a=''||...) && (...||...||...| |$b=''||...)&&
..... (...||...||...| |$z=''||...))

will be always true as Janwillem Borleffs mentioned.
Maybe you meant $Post['Link']=='' in your code?

Jun 27 '06 #4
In message <vQ************ ******@newsfe3-win.ntli.net>, Ian Davies
<ia********@vir gin.net> writes
Can anyone tell me why the following code will NOT work
The error message should be displayed when there is something in both fields

if ((isset($_POST['Link']) && $_POST['Link'] !=='') &&
(isset($_POS T['uploadedfile']) && $_POST['uploadedfile'] !=='')) {
$error_msg.="<b r>You can't select to upload a link and a file at the same
time.";
Here you're using $_POST['uploadedfile']. I'd guess it should probably
be $_FILES['uploadedfile']['name'], which is the name of the file that
was uploaded.
curiously the following works

if(empty($_POST['Link']) || $_POST['Link'] ='' &&
empty($_FILE S['uploadedfile']) || $_FILES['uploadedfile'] ='') {
$error_msg.="<b r>You didn't select whether to upload a link or a file.";
}


Here you're using $_FILES['uploadedfile'], which would be an array.

And $_POST['Link'] ='' will always be true because it is giving
$_POST['Link'] the value ''.
--
Martin Jay
Phone/SMS: +44 7740 191877
Fax: +44 870 915 2124
Jun 27 '06 #5
Yes there was syntax errors in my previous post but i tried every
combination even with the correct syntax. The problem was the

$_FILES['uploadedfile']

which wasnt being recognised as a field
I found eventually that it should be

$_FILES['uploadedfile'] [Name]

now everything is fine
Thanks for the help

Ian

should be
if($_POST['Link']!=='' && $_FILES['uploadedfile']!=='') {
$error_msg.="<b r>You can't select to upload a link and a file at the same
time.";
}

error does shows when 'uploadedfile' is empty

if($_POST['Link']<>'' && $_FILES['uploadedfile']<>'') {
$error_msg.="<b r>You can't select to upload a link and a file at the same
time.";
}

error does shows when 'uploadedfile' is empty

if(!isset($_POS T['Link']) && !isset($_FILES['uploadedfile'])) {
$error_msg.="<b r>You can't select to upload a link and a file at the same
time.";
}

error does not show even when both fields have something in them
error does not show

"Martin Jay" <ma****@spam-free.org.uk> wrote in message
news:AP******** ******@spam-free.org.uk...
In message <vQ************ ******@newsfe3-win.ntli.net>, Ian Davies
<ia********@vir gin.net> writes
Can anyone tell me why the following code will NOT work
The error message should be displayed when there is something in both fields
if ((isset($_POST['Link']) && $_POST['Link'] !=='') &&
(isset($_POS T['uploadedfile']) && $_POST['uploadedfile'] !=='')) {
$error_msg.="<b r>You can't select to upload a link and a file at the sametime.";


Here you're using $_POST['uploadedfile']. I'd guess it should probably
be $_FILES['uploadedfile']['name'], which is the name of the file that
was uploaded.
curiously the following works

if(empty($_POST['Link']) || $_POST['Link'] ='' &&
empty($_FILE S['uploadedfile']) || $_FILES['uploadedfile'] ='') {
$error_msg.="<b r>You didn't select whether to upload a link or a file.";
}


Here you're using $_FILES['uploadedfile'], which would be an array.

And $_POST['Link'] ='' will always be true because it is giving
$_POST['Link'] the value ''.
--
Martin Jay
Phone/SMS: +44 7740 191877
Fax: +44 870 915 2124

Jun 27 '06 #6
Guy
Ian Davies a crit :
Hi

Can anyone tell me why the following code will NOT work
The error message should be displayed when there is something in both fields

if ((isset($_POST['Link']) && $_POST['Link'] !=='') &&
(isset($_POST['uploadedfile']) && $_POST['uploadedfile'] !=='')) {
$error_msg.="<b r>You can't select to upload a link and a file at the same
time.";

curiously the following works

if(empty($_POST['Link']) || $_POST['Link'] ='' && Hi
= is not operator; try ==
empty($_FILES['uploadedfile']) || $_FILES['uploadedfile'] ='') {
idem
G
$error_msg.="<b r>You didn't select whether to upload a link or a file.";
}

to display a message when there is nothing in both fields

help gratefuly requested
Ian

Jun 27 '06 #7

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

Similar topics

5
1507
by: Ray Gibbon | last post by:
Testing conditions. Common scenario. Old programmer, new to Python, love it, but still hankering after some of my old ways. Of all of it's 'new to me' features, I appear to be enjoying 'no declarations' and mixing types with abandon. In particular I find myself writing functions which return whatever might be useful in whatever type...
6
3242
by: Shabam | last post by:
A web application of mine developed using C# + MS SQL runs fine normally. However when I stress test it with a load testing software (using about 60 simultaneous users) some instances start erroring out. I see two different errors. One is a "Object reference not set to an instance of an object." error, which appears to always contain the...
16
2662
by: Suzanne Vogel | last post by:
Hi, I've been trying to write a function to test whether one class is derived from another class. I am given only id's of the two classes. Therefore, direct use of template methods is not an option. Let's call the id of a class "cid" (for "class id"). The function signature should look like this:...
1
2516
by: DS | last post by:
I'm setting up a sub-form on a form, whenever I go to link the Sub to the Main I get this message... "Parts of the Link with Missing Pair Fields Ignored" Does anyone know what the means and how to fix this? Thanks DS
3
1594
by: Shawn | last post by:
Hello all... I'm new to the world of C programming, and am working with an embedded microcontroller as a hobby. I have a reasonably simple program running now, but I'm having trouble figuring out how to test for a specific bit when an interrupt is triggered. Basically when the interrupt is set, the program reads a register to determine...
72
5204
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: http://geosoft.no/development/unittesting.html Thanks.
1
1821
by: UserX | last post by:
I have several macro's, but some of then only have to run when a specific condition is true. Example: Macro1 : Load table1 Macro2 : Open form to complete empty fields in table1 Macro3 : Load table2 ....
13
1457
by: Ian Davies | last post by:
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 && isset($_POST)){ die('You can\'t select to upload a link and a file at the same time.'); } else { STUFF HERE;
0
8205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
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 we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.