469,571 Members | 1,272 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,571 developers. It's quick & easy.

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

names of
radio buttons: groupname - 'rdoAuctionType', with 'fixed',
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:
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.</
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.</
else if(trim($bidincrement) == '') {
$errmsg .= '<li>Please enter your bid increment.</li>';
else if(!isNumber($bidincrement)) {
$errmsg .= '<li>Bid increment should only contain numbers.</
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:

<form name="formRegister" action="add_auction.php" method="post">
<label>Auction Type:</label>
<table border="0">
<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>

<input type="textbox" size="4" name="txtDuration" value="<?echo
<option value="day">Day(s)</option>
<option value="week">Week(s)</option>
<option value="month">Month(s)</option></select><br>
<td>&nbsp;</td><td><input type="submit" name="btnConfirm"
value="Confirm"><input type="reset" name="btnReset" value="Reset"></

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 7007
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stephane Ninin | last post: by
2 posts views Thread by Prakash C via .NET 247 | last post: by
2 posts views Thread by Colin Nicholls | last post: by
reply views Thread by hammad.awan_nospam | last post: by
2 posts views Thread by Rui Maciel | last post: by
1 post views Thread by napolpie | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.