Re: [PHP] empty() in email message

2010-12-22 Thread Ravi Gehlot
Hello Gary,

Please research the difference between a single quote and a double quote.
Also, you can use the operator .=(dot + equal) in this manner:

if(!empty($_POST['fname'])) {
$msg .= $lname\n;
} else if(!empty($_POST['lname'])) {
$msg .= $lname\n;
}



On Tue, Dec 14, 2010 at 12:04 AM, Gary gp...@paulgdesigns.com wrote:


 Daevid Vincent dae...@daevid.com wrote in message
 news:7d7c84d94dd24035a620e68b5b937...@mascorp.com...
  - Original message -
  From: Gary gp...@paulgdesigns.com
  To: php-general@lists.php.net php-general@lists.php.net
  Date: Monday, December 13, 2010, 7:47:49 PM
  Subject: [PHP] 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




[PHP] empty() in email message

2010-12-13 Thread Gary
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'}

But I am getting the error

Parse error: syntax error, unexpected T_IF

Can someone point me in the right direction?

Thank you
-- 
Gary 



__ Information from ESET Smart Security, version of virus signature 
database 5699 (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



Re: [PHP] empty() in email message

2010-12-13 Thread Bastien Koert
On Mon, Dec 13, 2010 at 12:47 PM, Gary gp...@paulgdesigns.com wrote:
 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'}

 But I am getting the error

 Parse error: syntax error, unexpected T_IF

 Can someone point me in the right direction?

 Thank you
 --
 Gary



 __ Information from ESET Smart Security, version of virus signature 
 database 5699 (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



Less complication is better, reduce the code to the below. The empty
portion needs to be inside the parentheses. Also double quotes are
needed to make the vairable parse correctly into the value you want to
see

if (!empty($beefolives)) { echo Order: beefolives $beefolives\n;}


-- 

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] empty() in email message

2010-12-13 Thread a...@ashleysheridan.co.uk
How are these variables being given their values by php? If you're making use 
of register_globals then you're asking for problems.

Perform some sanity checks on your data, like using a regex of /^\d+$/ to check 
for numerical values, and turn globals off; its a security breach waiting to 
happen.

Get the values from $_GET or $_POST and treat each one as malicious until you 
know its within the bounds of your application as a real value.

Thanks,
Ash
http://www.ashleysheridan.co.uk

- Reply message -
From: Gary gp...@paulgdesigns.com
Date: Mon, Dec 13, 2010 17:47
Subject: [PHP] empty() in email message
To: php-general@lists.php.net

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'}

But I am getting the error

Parse error: syntax error, unexpected T_IF

Can someone point me in the right direction?

Thank you
-- 
Gary 



__ Information from ESET Smart Security, version of virus signature 
database 5699 (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



Re: [PHP] empty() in email message

2010-12-13 Thread Paul M Foster
On Mon, Dec 13, 2010 at 12:47:49PM -0500, Gary wrote:

 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'}
 
 But I am getting the error
 
 Parse error: syntax error, unexpected T_IF
 
 Can someone point me in the right direction?

It looks like you're trying to do something like:

$str = 'something' . 
if ($somethingelse)
'another string'
else
'a different string';

For one thing, you can't put a conditional on the right side of a
concatenation mark (.). You'd have to do it this way:

$str = 'something';
if ($somethingelse) {
$str .= 'another string';
}
else {
$str .= 'a different string';
}

You also can't do:

elseif (isset($beefolives)) {
'Order: beefolives $beefolives\n';
}

For one thing, surrounding the 'Order...' line with single quotes will
cause the \n *not* to be interpreted as a newline. Second, your 'Order:
beefolives...' does nothing. You haven't assigned it to anything or
operated on that string in any way.

You might want to study up on single versus double quotes, the
concatenation operator (.), etc.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] empty() in email message

2010-12-13 Thread Daniel P. Brown
On Mon, Dec 13, 2010 at 12:47, Gary gp...@paulgdesigns.com wrote:
 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'}

 But I am getting the error

 Parse error: syntax error, unexpected T_IF

 Can someone point me in the right direction?

That's because you're concatenating.  When appending to a
variable, you can't use constructs and conditions, unless using
ternaries:

. (!empty($beefolives)  is_numeric($beefolives) ? 'Order: beefolives
'.$beefolives : null)

However, for readability and ease of management, you might want to
try something like this.  It makes at least two assumptions: you're
using a form post, and you understand that it's untested (as I'm just
typing it here into the body of this email).

?php
// If we've posted our order
if (isset($_POST)  is_array($_POST['order'])) {

// Instantiate the $order variable
$order = null;

// Iterate the order quantities
foreach ($_POST['order'] as $k = $v) {

// If the field is set and the amount is a number
if (isset($v)  is_numeric($v)) {

$order .= 'Order: '.$k.': '.$v.PHP_EOL;
}
}

/**
 * Note: in your example, you used single (literal)
 * quotes and included the variables.  That would
 * literally print $fname and $lname.
 */
$msg  = 'Name: '.$_POST['fname'].' '.$_POST['lname'].PHP_EOL;
$msg .= 'Phone: '.$_POST['phone'].PHP_EOL;
$msg .= 'Email: '.$_POST['email'].PHP_EOL;
$msg .= PHP_EOL;
$msg .= $order;

// And then handle the rest of your processing.  Here, we just echo.
echo 'pre'.PHP_EOL.$msg.'/pre'.PHP_EOL;
}
?
form method=post action=?php echo $_SERVER['PHP_SELF']; ?
First Name: input type=text name=fname id=fnamebr/
Last Name: input type=text name=lname id=lnamebr/
Phone: input type=text name=phone id=phonebr/
Email: input type=text name=email id=emailbr/
br /

h3Order/h3

Beef Schnitzel: input type=text name=order[beefschnitzel]
id=order[beefschnitzel] size=2 maxlength=3br/
Beef Strips: input type=text name=order[beefstrips]
id=order[beefstrips] size=2 maxlength=3br/
Cheese Sausage: input type=text name=order[cheesesausage]
id=order[cheesesausage] size=2 maxlength=3br/
Crumbed Sausage: input type=text name=order[crumbedsausage]
id=order[crumbedsausage] size=2 maxlength=3br/
Chuck Steak: input type=text name=order[chucksteak]
id=order[chucksteak] size=2 maxlength=3br/
Corned Beef: input type=text name=order[cornedbeef]
id=order[cornedbeef] size=2 maxlength=3br/
Diced Steak: input type=text name=order[dicedsteak]
id=order[dicedsteak] size=2 maxlength=3br/
Filet Mignon: input type=text name=order[filletmignon]
id=order[filletmignon] size=2 maxlength=3br/
!-- NOTE: Filet as displayed on the form has one 'L', but the
variable is unchanged. --
br /

input type=submit value=Order Now
/form

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] empty() in email message

2010-12-13 Thread Andre Polykanine
Hello Gary,

Try using this:
if (!empty($beefolives)) $msg.=Order: beef olives;
or:
$msg.=empty($beefolives)? : Order: beef olives;

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

- Original message -
From: Gary gp...@paulgdesigns.com
To: php-general@lists.php.net php-general@lists.php.net
Date: Monday, December 13, 2010, 7:47:49 PM
Subject: [PHP] 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'}

But I am getting the error

Parse error: syntax error, unexpected T_IF

Can someone point me in the right direction?

Thank you
-- 
Gary 



__ Information from ESET Smart Security, version of virus signature 
database 5699 (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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] empty() in email message

2010-12-13 Thread Daevid Vincent
 - Original message -
 From: Gary gp...@paulgdesigns.com
 To: php-general@lists.php.net php-general@lists.php.net
 Date: Monday, December 13, 2010, 7:47:49 PM
 Subject: [PHP] 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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] empty() in email message

2010-12-13 Thread Gary

Bastien Koert phps...@gmail.com wrote in message 
news:aanlktimimt6h+g+zg4a_78wls4bu09zzsa3jvdujj...@mail.gmail.com...
On Mon, Dec 13, 2010 at 12:47 PM, Gary gp...@paulgdesigns.com wrote:
 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'}

 But I am getting the error

 Parse error: syntax error, unexpected T_IF

 Can someone point me in the right direction?

 Thank you
 --
 Gary



 __ Information from ESET Smart Security, version of virus 
 signature database 5699 (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



Less complication is better, reduce the code to the below. The empty
portion needs to be inside the parentheses. Also double quotes are
needed to make the vairable parse correctly into the value you want to
see

if (!empty($beefolives)) { echo Order: beefolives $beefolives\n;}


-- 

Bastien

Bastien

Thank you for your response, and I agree, I like simpler.  Your script 
however did not work in the email message, it did work in another section 
where I echo to screen the information to the screen.

Does the echo command work in emails?

Thank you again.

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



Re: [PHP] empty() in email message

2010-12-13 Thread Gary

Daniel P. Brown daniel.br...@parasane.net wrote in message 
news:aanlktikw+h1nvf6tcg5hgh-2xsubtuosvgkwaynb=...@mail.gmail.com...
On Mon, Dec 13, 2010 at 12:47, Gary gp...@paulgdesigns.com wrote:
 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'}

 But I am getting the error

 Parse error: syntax error, unexpected T_IF

 Can someone point me in the right direction?

That's because you're concatenating.  When appending to a
variable, you can't use constructs and conditions, unless using
ternaries:

. (!empty($beefolives)  is_numeric($beefolives) ? 'Order: beefolives
'.$beefolives : null)

However, for readability and ease of management, you might want to
try something like this.  It makes at least two assumptions: you're
using a form post, and you understand that it's untested (as I'm just
typing it here into the body of this email).

?php
// If we've posted our order
if (isset($_POST)  is_array($_POST['order'])) {

// Instantiate the $order variable
$order = null;

// Iterate the order quantities
foreach ($_POST['order'] as $k = $v) {

// If the field is set and the amount is a number
if (isset($v)  is_numeric($v)) {

$order .= 'Order: '.$k.': '.$v.PHP_EOL;
}
}

/**
* Note: in your example, you used single (literal)
* quotes and included the variables.  That would
* literally print $fname and $lname.
*/
$msg  = 'Name: '.$_POST['fname'].' '.$_POST['lname'].PHP_EOL;
$msg .= 'Phone: '.$_POST['phone'].PHP_EOL;
$msg .= 'Email: '.$_POST['email'].PHP_EOL;
$msg .= PHP_EOL;
$msg .= $order;

// And then handle the rest of your processing.  Here, we just echo.
echo 'pre'.PHP_EOL.$msg.'/pre'.PHP_EOL;
}
?
form method=post action=?php echo $_SERVER['PHP_SELF']; ?
First Name: input type=text name=fname id=fnamebr/
Last Name: input type=text name=lname id=lnamebr/
Phone: input type=text name=phone id=phonebr/
Email: input type=text name=email id=emailbr/
br /

h3Order/h3

Beef Schnitzel: input type=text name=order[beefschnitzel]
id=order[beefschnitzel] size=2 maxlength=3br/
Beef Strips: input type=text name=order[beefstrips]
id=order[beefstrips] size=2 maxlength=3br/
Cheese Sausage: input type=text name=order[cheesesausage]
id=order[cheesesausage] size=2 maxlength=3br/
Crumbed Sausage: input type=text name=order[crumbedsausage]
id=order[crumbedsausage] size=2 maxlength=3br/
Chuck Steak: input type=text name=order[chucksteak]
id=order[chucksteak] size=2 maxlength=3br/
Corned Beef: input type=text name=order[cornedbeef]
id=order[cornedbeef] size=2 maxlength=3br/
Diced Steak: input type=text name=order[dicedsteak]
id=order[dicedsteak] size=2 maxlength=3br/
Filet Mignon: input type=text name=order[filletmignon]
id=order[filletmignon] size=2 maxlength=3br/
!-- NOTE: Filet as displayed on the form has one 'L', but the
variable is unchanged. --
br /

input type=submit value=Order Now
/form

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

Daniel

As always, thank you for your input. I had tried your first script, and it 
worked to a degree.  What I was getting was a message that was correct, but, 
well, this is what it looked like in an email

Order: beefschnitzel
10Order:

Which was supposed to look like

Order: beefschnitzel 10

Order:

I have not tried your second suggestion yet, I'll let you know how that 
works.

Again, 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



Re: [PHP] empty() in email message

2010-12-13 Thread Gary

Paul M Foster pa...@quillandmouse.com wrote in message 
news:20101213181124.gq21...@quillandmouse.com...
 On Mon, Dec 13, 2010 at 12:47:49PM -0500, Gary wrote:

 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'}

 But I am getting the error

 Parse error: syntax error, unexpected T_IF

 Can someone point me in the right direction?

 It looks like you're trying to do something like:

 $str = 'something' .
 if ($somethingelse)
 'another string'
 else
 'a different string';

 For one thing, you can't put a conditional on the right side of a
 concatenation mark (.). You'd have to do it this way:

 $str = 'something';
 if ($somethingelse) {
 $str .= 'another string';
 }
 else {
 $str .= 'a different string';
 }

 You also can't do:

 elseif (isset($beefolives)) {
 'Order: beefolives $beefolives\n';
 }

 For one thing, surrounding the 'Order...' line with single quotes will
 cause the \n *not* to be interpreted as a newline. Second, your 'Order:
 beefolives...' does nothing. You haven't assigned it to anything or
 operated on that string in any way.

 You might want to study up on single versus double quotes, the
 concatenation operator (.), etc.

 Paul

 -- 
 Paul M. Foster



Paul

Thank you for your reponse.  I will admit I get a little fuzzy on the single 
v double quotation marks, generally the rule I go by is if it is a string, I 
use singles, if any processing I use doubles.  I am not recalling why did it 
that way, perhaps I had doubles and it did not work so I was whittling down 
the options

Thank you again 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



Re: [PHP] empty() in email message

2010-12-13 Thread Gary

Andre Polykanine an...@oire.org wrote in message 
news:1110253876.20101214025...@oire.org...
 Hello Gary,

 Try using this:
 if (!empty($beefolives)) $msg.=Order: beef olives;
 or:
 $msg.=empty($beefolives)? : Order: beef olives;

 -- 
 With best regards from Ukraine,
 Andre
 Skype: Francophile
 Twitter: http://twitter.com/m_elensule
 Facebook: http://facebook.com/menelion

 - Original message -
 From: Gary gp...@paulgdesigns.com
 To: php-general@lists.php.net php-general@lists.php.net
 Date: Monday, December 13, 2010, 7:47:49 PM
 Subject: [PHP] 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'}

 But I am getting the error

 Parse error: syntax error, unexpected T_IF

 Can someone point me in the right direction?

 Thank you
 -- 
 Gary



Andre

That looks good, I will give that a try in the morning, 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



Re: [PHP] empty() in email message

2010-12-13 Thread Gary

Daevid Vincent dae...@daevid.com wrote in message 
news:7d7c84d94dd24035a620e68b5b937...@mascorp.com...
 - Original message -
 From: Gary gp...@paulgdesigns.com
 To: php-general@lists.php.net php-general@lists.php.net
 Date: Monday, December 13, 2010, 7:47:49 PM
 Subject: [PHP] 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