""Daevid Vincent"" <daevid@xxxxxxxxxx> wrote in message news:7D7C84D94DD24035A620E68B5B937E16@xxxxxxxxxxxxxx >> ----- Original message ----- >> From: Gary <gpaul@xxxxxxxxxxxxxxxx> >> To: php-general@xxxxxxxxxxxxx <php-general@xxxxxxxxxxxxx> >> Date: Monday, December 13, 2010, 7:47:49 PM >> Subject: empty() in email message >> >> I have an email message >> >> $msg = 'Name: $fname ' . ' $lname\n' >> . "Phone: $phone\n" >> . "Email: $email\n" >> >> and it works fine, however in this message there are about 30 >> variables that >> are being called...as such >> >> . "Order: beefschnitzel $beefschnitzel\n" >> . "Order: beefstrips $beefstrips\n" >> . "Order: cheesesausage $cheesesausage\n" >> . "Order: crumbedsausage $crumbedsausage\n" >> . "Order: chucksteak $chucksteak\n" >> . "Order: cornedbeef $cornedbeef\n" >> . "Order: dicedsteak $dicedsteak\n" >> . "Order: filletmignon $filletmignon\n" >> >> I want to only send the message if the submitter enters an >> amount in the >> form for the corresponding variable, instead of having a >> bunch of empty >> messages. So I have been trying to use the empty() function as such: >> >> . if empty($beefolives){''} elseif (isset($beefolives)) { >> 'Order: beefolives >> $beefolives\n'} > > You are setting this up fundamentally wrong. > > You should be using an array and looping through it. > > Something like: > > $myorder['cowface'] = 1; > $myorder['beefenweiner'] = 2; > $myorder['chucksteak'] = 1; > > foreach ($myorder as $item => $quantity) > { > echo "Order: $item x $quantity\n"; > } > > Then your array only contains the items someone actually puchased and how > many. > > d > Daevid I knew someone was going to point out this was a convoluted method, and I agree. This was sent to me by someone that needed to make the mail form work. My suggestion was to look into a pre-made shopping cart, however that was not going to work for them, so I made the mail() work for them. I had thought about putting it into an array, but had not gotten that far into it. I will look over the code to see how it works. Thank you for your help. gary __________ Information from ESET Smart Security, version of virus signature database 5700 (20101213) __________ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php