473,385 Members | 1,546 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,385 software developers and data experts.

Problem with nested if-else statement

I'm setting up an auction website using PHP and MySQL. There in the
section where logged in members can put up new auction in a form, I
want to run a form validation where I used if else statements to check
the fileds filled. In the form page there are two radio buttons -
fixed and auction - (only one can be chosen) and depend upon which one
is chosen some text should be inserted in the text fields. For that
I'm using a validation where this nested if else is not working
properly. It checks until some if statements then won't check the rest
of the if statements. The codes below I have reduced to relevant
parts.

names of
radio buttons: groupname - 'rdoAuctionType', with 'fixed',
'auction'
text fields:
when 'fixed' button is selected, text field 'txtFixedPrice'
must be filled
when 'auction' button is selected, text fields
'txtStartPrice' and 'txtIncrement' must be filled
---------------------------------------------------------------------------*------------------------------------------------------------
Here is the code:
auction_formvalidation.php
if(isset($_POST['btnConfirm'])) {
.............
.............
$auctiontype = $_POST['rdoAuctionType'];
$fixedprice = $_POST['txtFixedPrice'];
$startprice = $_POST['txtStartPrice'];
$bidincrement = $_POST['txtIncrement'];
$duration = $_POST['txtDuration'];
...........
if {
.....
}
else if {
......
}
else if(trim($auctiontype) != '') {
if(trim($auctiontype) == 'fixed') {
if(trim($fixedprice) == '') {
$errmsg .= '<li>Please enter the fixed price.</li>';
}
else if(!isNumber($fixedprice)){
$errmsg .= '<li>Fixed price should only contain numbers.</
li>';
}
}
else if(trim($auctiontype) == 'auction'){
if(trim($startprice) == '') {
$errmsg .= '<li>Please enter the start price.</li>';
}
else if(!isNumber($startprice)) {
$errmsg .= '<li>Start price should only contain numbers.</
li>';
}
else if(trim($bidincrement) == '') {
$errmsg .= '<li>Please enter your bid increment.</li>';
}
else if(!isNumber($bidincrement)) {
$errmsg .= '<li>Bid increment should only contain numbers.</
li>';
}
}
}
else if(trim($duration) == '') { <----------------- it doent check
from here ownwards
$errmsg .= '<li>Please enter the duration for the auction.</li>';
}
else if {
.......
}

}
Code of form page:
add_auction.php

<html>
..............
..............
<form name="formRegister" action="add_auction.php" method="post">
<fieldset>
...............
...............
...............
<label>Auction Type:</label>
<table border="0">
<tr>
<td valign="top"><input type="radio" name="rdoAuctionType"
value="fixed" <?if ($auctiontype == 'fixed') echo "checked";?
>Fixed<br>Fixed Price:<input type="textbox" name="txtFixedPrice"
size="8" value="<?echo $fixedprice?>"></td <td><input
type="radio" name="rdoAuctionType" value="auction" <?if ($auctiontype
== 'auction') echo "checked";?>>;">Auction<br>Starting Price:<input
type="textbox" name="txtStartPrice" size="8" value="<? echo
$startprice?>"><br>Bid Increment:<input type="textbox"
name="txtIncrement" size="5" value="<?echo $bidincrement?>"></td>
</tr>
</table>

<label>Duration:</label>
<input type="textbox" size="4" name="txtDuration" value="<?echo
$duration?>"
<select>
<option value="day">Day(s)</option>
<option value="week">Week(s)</option>
<option value="month">Month(s)</option></select><br>
................
...............
<table>
<tr>
<td>&nbsp;</td><td><input type="submit" name="btnConfirm"
value="Confirm"><input type="reset" name="btnReset" value="Reset"></
td>
</tr>
</table>
</fieldset>
</form>
............
.............
</html>
---------------------------------------------------------------------------*------------------------------------------------------------

I have posted this in some other group, but until now didn't get any
reply. So I thought to put it here too. Am I in the right place? :s

Could somebody help me? I would be thankful :)

May 23 '07 #1
2 7199
Message-ID: <11**********************@k79g2000hse.googlegroups .comfrom
Ravi contained the following:
>use empty($duration).and check weather that variable is existed or not
first.check it with isset($duration).
empty() does both. Not clear in the documentation but example 2503
indicates this is the case.

--
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/
May 23 '07 #2
Sorry for late reply. My laptop got defect, and I couldnt do further
on that work. Now borrowed my friends and continuing on my work.

Thanks for the help. But I tried empty($duration) but still no change.
Then I don't understand why it works with other trim() statements and
this one not. Are you sure the if-else statement is written correctly?

May 30 '07 #3

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

Similar topics

1
by: Stephane Ninin | last post by:
Hello all, I am trying to play with nested class in a script I am making, and I am not sure I really understand how they work. Here is some code: __all__ =
2
by: Prakash C via .NET 247 | last post by:
Hi, I am having a problem to create nested collections. I want tocreate a menu for my site. I created a MenuItem class which willstore the text that should appear on hyperlink. It may alsocontain...
2
by: Colin Nicholls | last post by:
Platform: ASP.NET 1.1 I have a repeater nested inside another repeater. My outer repeater is looping fine. I am manually binding the inner repeater to a DataReader obtained from another...
7
by: Ryan Shaw | last post by:
I’m having a small problem with inheritance with a hierarchy of classes The example is Class Class Private m_classB as Class Class Class End Clas End Clas
1
by: Tomas Sieger | last post by:
Hi all, I'm in doubt with the following code: class Base { public: class Nested {}; }; class Derived:public Base { public: class Nested {
0
by: hammad.awan_nospam | last post by:
Hello, I am using ASP.NET 2.0. What I have done is nested a gridview inside another column of a gridview using a template data field column declaritively in my web form. Inside this child...
2
by: Rui Maciel | last post by:
I've been fooling around with a test class and meanwhile I stumbled on a pointer problem. I have two classes, one being nested in the other. I've wrote a method in the nested class that would...
1
by: imranpariyani | last post by:
Hi i have a severe performance problem with one of my views which has 6 to 8 joins .. any help will be appreciated.. the view is: CREATE OR REPLACE VIEW thsn.trade_view AS SELECT...
1
by: napolpie | last post by:
----Messaggio originale---- Da: napolpie@tin.it Data: 3-mag-2007 10.02 A: <python-list@python.org> Ogg: problem with meteo datas Hello, I'm Peter and I'm new in python codying and I'm using...
2
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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.