Re: Re: A tricky one?
| From: | Justin French | Date: | Mon, 03 Dec 2001 01:12:08 +0000 |
| Subject: | Re: Re: A tricky one? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-76361@lists.php.net to get a copy of this message | ||
Basically, you want to do is evaluate if they entered anything for each
item, and if so, print an additional line to the message.
<?
$message = "I would like to order:\n";
if($pizza != "") { $message .= "Pizza: $pizza \n"; }
if($chips != "") { $message .= "Chips: $chips \n"; }
if($hamburger != "") { $message .= "Hamburger: $hamburger \n"; }
?>
Explanation:
$message .= "blah"; appends "blah" onto the end of the string $message
\n is a new line (I dunno, you might be a newbie!!)
If they entered 2 hamburgers and one pizza into the form, then the
result of $message would be:
---
I would like to order:
Pizza: 1
Hamburger: 2
---
I think you get the drift.
There are DEFINATELY better ways to write this code, but it's the
simplest to understand.
Justin French
Raymond Lilleodegard wrote:
>
> Thanks for answering.
>
> But this only works if the customer orders one of each. Do you know how to
> do it if, lets say the customer order 2 hamburgers and nothing else?
>
> Raymond
>
> "Raymond LilleøDegåRd" <raymond@lilleodegard.com> wrote in message
> news:20011120174423.84798.qmail@pb1.pair.com...
> > Hi!
> >
> > I'm trying to make this form working with a mail() script.
> > I made this form. Then the customer could write how many "pizzas" or
> > "hamburgers" as he want.
> > But how do I solve this without too much headache? Havent slept for days
> > because of this problem : )
> >
> >
> > <input type="text" name="pizza">
> > <input type="text" name="chips">
> > <input type="text" name="hamburger">
> >
> >
> > -------- script ----------------
> > <?php
> > /* recipients */
> > $to = "someone@online.no" ;
> >
> > /* subject */
> > $subject = "Order";
> >
> > /* message */
> > $message = "I would like to order $?";
> >
> > /* To send HTML mail, you can set the Content-type header. */
> >
> > /* additional headers */
> > $headers = "From: Someone <someone@someone.com>\r\n";
> >
> >
> > /* and now mail it */
> > mail($to, $subject, $message, $headers);
> >
> >
> > Best regards
> >
> > Raymond
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net