[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 06-23-2006, 03:28 PM   #1 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 133
10.00 NP$ (Donate)

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) == 1 ) {
echo
'<font color=#ff0000>';
echo
'You did not enter an amount for tires <br /><br />';
echo
'</font>';

if ( empty(
$oilqty) == 1 ){
echo
'<font color=#ff0000>';
echo
'You did not enter an amount for oil <br /><br />';
echo
'</font>';


if ( empty(
$sparkqty) == 1 ){
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, 03:42 PM   #2 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,546
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Something like this?
PHP Code:
<?php

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, 03:57 PM   #3 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 133
10.00 NP$ (Donate)

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) == 1 || empty($oilqty) == 1 ||  empty($sparkqty) == 1 )
{
echo
'<font color=#ff0000>';
echo
'You didnt enter the following fields: <br />';
if(empty(
$tireqty) == 1 )
   { echo
'tires<br />'; }
if(empty(
$oilqty) == 1 ){echo 'oil<br />'; }
if(empty(
$sparkqty) == 1 ){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, 04:05 PM   #4 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,546
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 01:22 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85