473,378 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

multiple parameters in if statement...

Kun
I am trying to make an if-statement that will not do anything and print
'nothing entered' if there is nothing entered in a form. I have the
following code that does that, however, now even if I enter something
into the form, the code still outputs 'nothing entered'. This violates
the if statement and I am wondering what I did wrong.

if form.has_key("delete_id") and form["delete_id"].value != "" and
form.has_key("delete_date") and form["delete_date"].value != "" and
form.has_key("delete_purchasetype") and
form["delete_purchasetype"].value != "" and form.has_key("delete_price")
and form["delete_price"].value != "" and form.has_key("delete_comment")
and form["delete_comment"].value != "":
delete_id=form['delete_id'].value
delete_date=form['delete_date'].value
delete_purchasetype=form['delete_purchasetype'].value
delete_price=form['delete_price'].value
delete_comment=form['delete_comment'].value
else:
print "ERROR: Nothing entered!"
raise Exception
Apr 16 '06 #1
3 1776

Kun wrote:
I am trying to make an if-statement that will not do anything and print
'nothing entered' if there is nothing entered in a form. I have the
following code that does that, however, now even if I enter something
Yes, but did you enter everything?
into the form, the code still outputs 'nothing entered'.
The logic doesn't imply "nothing", it implies "not everything".
The else clause will execute if ANY item is not enetered.
This violates
the if statement and I am wondering what I did wrong.

if form.has_key("delete_id") and form["delete_id"].value != "" and
form.has_key("delete_date") and form["delete_date"].value != "" and
form.has_key("delete_purchasetype") and
form["delete_purchasetype"].value != "" and form.has_key("delete_price")
and form["delete_price"].value != "" and form.has_key("delete_comment")
and form["delete_comment"].value != "":
delete_id=form['delete_id'].value
delete_date=form['delete_date'].value
delete_purchasetype=form['delete_purchasetype'].value
delete_price=form['delete_price'].value
delete_comment=form['delete_comment'].value
else:
print "ERROR: Nothing entered!"
raise Exception


Apr 16 '06 #2
Kun
me********@aol.com wrote:
Kun wrote:
I am trying to make an if-statement that will not do anything and print
'nothing entered' if there is nothing entered in a form. I have the
following code that does that, however, now even if I enter something


Yes, but did you enter everything?
into the form, the code still outputs 'nothing entered'.


The logic doesn't imply "nothing", it implies "not everything".
The else clause will execute if ANY item is not enetered.
This violates
the if statement and I am wondering what I did wrong.

if form.has_key("delete_id") and form["delete_id"].value != "" and
form.has_key("delete_date") and form["delete_date"].value != "" and
form.has_key("delete_purchasetype") and
form["delete_purchasetype"].value != "" and form.has_key("delete_price")
and form["delete_price"].value != "" and form.has_key("delete_comment")
and form["delete_comment"].value != "":
delete_id=form['delete_id'].value
delete_date=form['delete_date'].value
delete_purchasetype=form['delete_purchasetype'].value
delete_price=form['delete_price'].value
delete_comment=form['delete_comment'].value
else:
print "ERROR: Nothing entered!"
raise Exception

How do I make this so that it only prints 'nothing entered' when none of
the fields are entered?
Apr 16 '06 #3
Kun wrote:
me********@aol.com wrote:
Kun wrote:
I am trying to make an if-statement that will not do anything and print
'nothing entered' if there is nothing entered in a form. I have the
following code that does that, however, now even if I enter something


Yes, but did you enter everything?
into the form, the code still outputs 'nothing entered'.


The logic doesn't imply "nothing", it implies "not everything".
The else clause will execute if ANY item is not enetered.
This violates
the if statement and I am wondering what I did wrong.

if form.has_key("delete_id") and form["delete_id"].value != "" and
form.has_key("delete_date") and form["delete_date"].value != "" and
form.has_key("delete_purchasetype") and
form["delete_purchasetype"].value != "" and form.has_key("delete_price")
and form["delete_price"].value != "" and form.has_key("delete_comment")
and form["delete_comment"].value != "":
delete_id=form['delete_id'].value
delete_date=form['delete_date'].value
delete_purchasetype=form['delete_purchasetype'].value
delete_price=form['delete_price'].value
delete_comment=form['delete_comment'].value
else:
print "ERROR: Nothing entered!"
raise Exception

How do I make this so that it only prints 'nothing entered' when none of
the fields are entered?


def has_data(form, fields):
for field in fields:
if form.has_key(field) and form[field] != "":
return True
return False

fields = ["delete_id", "delete_date", "delete_purchasetype", "delete_price",
"delete_comment"]

if not has_data(form, fields):
print "nothing entered"

Just testing for

if field in form: ...

instead of

if form.has_key(field) and form[field] != "": ...

is probably sufficient if form is a cgi.FieldStorage.

Peter

Apr 16 '06 #4

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

Similar topics

1
by: merdaad | last post by:
I am trying to read multiple rows from an SP into a datalist. I can easily read and display multiple rows if I use a select statement but when I call an SP to send me a few rows, I only get back...
11
by: Mike | last post by:
Looking to find any information on how to properly configure multiple instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking for information on how the multiple instance settings...
2
by: Mark Mullins | last post by:
have code below: Function ClassColl(strClass As Variant, strColl As Variant) As String ' Comments : ' Parameters : strClass ' strColl ' Returns : String Description '...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
3
by: Jesper Jensen | last post by:
I have the following problem: I have created the following SQL for my app. With the below shown code (Example 1) I am able to retrieve the records I need into dataset dsFind. Now however I want...
12
by: Dennis D. | last post by:
Hello: I want a function to return three variables to the calling procedure: Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as Integer, ByVal iAddMins as Integer) As...
4
by: arak123 | last post by:
consider the following oversimplified and fictional code public void CreateInvoices(Invoice invoices) { IDbCommand command=Util.CreateDbCommand(); foreach(Invoice invoice in invoices) //lets...
9
by: dan | last post by:
within a loop i am building a sql insert statement to run against my (programatically created) mdb. it works but it seems unreasonably SLOW! Sorry, dont have the code here but the jist is very...
7
by: Ceebaby via AccessMonster.com | last post by:
Hi All Here's hoping someone can help me with this. I have a report based on a query where the criteria for 4 of the fields is set from an unbound form. I want the user to be able to select any...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.