473,774 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_formval idation.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($auctio ntype) != '') {
if(trim($auctio ntype) == 'fixed') {
if(trim($fixedp rice) == '') {
$errmsg .= '<li>Please enter the fixed price.</li>';
}
else if(!isNumber($f ixedprice)){
$errmsg .= '<li>Fixed price should only contain numbers.</
li>';
}
}
else if(trim($auctio ntype) == 'auction'){
if(trim($startp rice) == '') {
$errmsg .= '<li>Please enter the start price.</li>';
}
else if(!isNumber($s tartprice)) {
$errmsg .= '<li>Start price should only contain numbers.</
li>';
}
else if(trim($bidinc rement) == '') {
$errmsg .= '<li>Please enter your bid increment.</li>';
}
else if(!isNumber($b idincrement)) {
$errmsg .= '<li>Bid increment should only contain numbers.</
li>';
}
}
}
else if(trim($durati on) == '') { <----------------- 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="formRegis ter" action="add_auc tion.php" method="post">
<fieldset>
...............
...............
...............
<label>Auctio n Type:</label>
<table border="0">
<tr>
<td valign="top"><i nput type="radio" name="rdoAuctio nType"
value="fixed" <?if ($auctiontype == 'fixed') echo "checked";?
>Fixed<br>Fix ed Price:<input type="textbox" name="txtFixedP rice"
size="8" value="<?echo $fixedprice?>"> </td <td><input
type="radio" name="rdoAuctio nType" value="auction" <?if ($auctiontype
== 'auction') echo "checked";?>>;" >Auction<br>Sta rting Price:<input
type="textbox" name="txtStartP rice" size="8" value="<? echo
$startprice?>"> <br>Bid Increment:<inpu t type="textbox"
name="txtIncrem ent" size="5" value="<?echo $bidincrement?> "></td>
</tr>
</table>

<label>Duration :</label>
<input type="textbox" size="4" name="txtDurati on" value="<?echo
$duration?>"
<select>
<option value="day">Day (s)</option>
<option value="week">We ek(s)</option>
<option value="month">M onth(s)</option></select><br>
............... .
...............
<table>
<tr>
<td>&nbsp;</td><td><input type="submit" name="btnConfir m"
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 7237
Message-ID: <11************ **********@k79g 2000hse.googleg roups.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
1586
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
1501
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 other properties. Then a MenuItems class which inheritscollection base and implements ienumerator. The MenuItems classholds a collection of MenuItem objects. Ok. Fine. Now, I will be having a nested menu, like Products ->Division -> Category ->...
2
2133
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 function. My objects aren't null, my ItemDataBound() method is being called, and as you can see I have verified that I have data. Yet, the repeater does not appear in the final HTML, and what's more, after
7
2420
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
2131
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
2209
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 gridview I have set an ItemStyle property of width 20% for the first templated field which contains a hyperlink control, and an ItemStyle of width 80% for the second templated field which contains a label. Both of these controls are databound to...
2
1863
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 set a nested class's member pointer as a pointer to an instance of the other class. Here is the code: <code> template <class tData> class Foo
1
3116
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 tra.tra_id, tra.per_id, tra.fir_id, tra.tra_dcn, tra.tra_startdate::date AS tra_startdate, tra.tra_enddate::date AS tra_enddate, tra.tra_highprice, tra.tra_lowprice, tra.tra_shares, tra.tra_marketvalue, tra.tra_commonsharesheld, tra.tra_directsharesheld,...
1
1562
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 parsying to
2
2830
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 comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10040
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
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
2
3611
muto222
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.