NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP Question

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 06-23-2006, 04:28 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: May 2006
Posts: 133
spacetrain will become famous soon enoughspacetrain will become famous soon enough
 



PHP Question


Hey,

I have the following code in a script:


PHP Code:
<?php
if ( empty($tireqty) == ) {
echo 
'<font color=#ff0000>';
echo 
'You did not enter an amount for tires <br /><br />';
echo 
'</font>';

if ( empty(
$oilqty) == ){
echo 
'<font color=#ff0000>';
????: NamePros.com http://www.namepros.com/programming/210175-php-question.html
echo 
'You did not enter an amount for oil <br /><br />';
echo 
'</font>';


if ( empty(
$sparkqty) == ){
echo 
'<font color=#ff0000>';
echo 
'You did not enter an amount for spark plugs <br /><br />';
echo 
'</font>';
include 
'orderform.html';
exit;
}
include 
'orderform.html';
exit;
}
include 
'orderform.html';
exit;
}
?>
What i want it to do is display a message when a value isnt entered into a field but i want to display an error for each missed field at once and if they arent there show the order form again instead of running the rest of the code. However with the code above if the first one exists it doesnt check for the rest of the statements and there must be an easier way than copying the next two into the else section?

Im learning php so i just want to know as i will probably use this in a future script.

Thanks
spacetrain is offline  
Old 06-23-2006, 04:42 PM   #2 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Something like this?
PHP Code:
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=210175

if (empty($tireqty))
{
    echo 
'<font color=#ff0000>You did not enter an amount for tires <br /><br /></font>';
    include 
'orderform.html';
}
else if (empty(
$oilqty))
{
    echo 
'<font color=#ff0000>You did not enter an amount for oil <br /><br /></font>';
    include 
'orderform.html';
}
else if (empty(
$sparkqty))
{
    echo 
'<font color=#ff0000>You did not enter an amount for spark plugs <br /><br /></font>';
    include 
'orderform.html';
}
else
{
    
// They are not empty
}

?>
Eric is offline  
Old 06-23-2006, 04:57 PM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: May 2006
Posts: 133
spacetrain will become famous soon enoughspacetrain will become famous soon enough
 



That would only display one error at a time, but thanks.

I managed to find a solution and edit it a bit, the code i used was:

PHP Code:
if ( empty($tireqty) == || empty($oilqty) == ||  empty($sparkqty) == )
{
echo 
'<font color=#ff0000>';
echo 
'You didnt enter the following fields: <br />';
if(empty(
$tireqty) == )
   { echo 
'tires<br />'; }
if(empty(
$oilqty) == ){echo 'oil<br />'; }
????: NamePros.com http://www.namepros.com/showthread.php?t=210175
if(empty(
$sparkqty) == ){echo 'spark plugs<br />'; }
echo 
'<br /><br />';
include 
'orderform.html';
exit;

Means it shows as:

You didnt enter the following fields
{lists every field not entered}
spacetrain is offline  
Old 06-23-2006, 05:05 PM   #4 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Oh, yes, sorry Glad ya figured it out.
Eric is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 08:25 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger