Re: [PHP] Re: A tricky one?
Basically, you want to do is evaluate if they entered anything for each item, and if so, print an additional line to the message. 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" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > 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 : ) > > > > > > > > > > > > > > > > script > > > /* recipients */ > > $to = "[EMAIL PROTECTED]" ; > > > > /* 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 <[EMAIL PROTECTED]>\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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: A tricky one?
switch the isset() with !empty() At 21:51 20/11/01 +0100, Raymond Lilleodegard wrote: >It works after modifying it a little. BUT... :) It lists all the variables >even if they aren't given any value. Is it possible to only get the defined >ones? > >Regards Raymond > > >"Matthew Luchak" <[EMAIL PROTECTED]> wrote in message >[EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > >how about... > > >$message=""; >$header="From: $email"; >$to="[EMAIL PROTECTED]"; >$subject="burger me"; > > while(list($var, $val) = each($HTTP_POST_VARS)) > { >if(($var !="email")&&($var !="SUBMIT")&&(isset($var)){$message >.="$val $var were ordered \n";} >} > >MAIL( >"$to", >"$subject", >"$message", >"$header" >); >?> > >Matthew Luchak >Webmaster >Kaydara Inc. >[EMAIL PROTECTED] > > >-Original Message- >From: Raymond Lilleodegard [mailto:[EMAIL PROTECTED]] >Sent: Tuesday, November 20, 2001 1:57 PM >To: [EMAIL PROTECTED] >Subject: [PHP] Re: A tricky one? > > >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" <[EMAIL PROTECTED]> wrote in message >[EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > 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 : ) > > > > > > > > > > > > > > > > script > > > /* recipients */ > > $to = "[EMAIL PROTECTED]" ; > > > > /* 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 <[EMAIL PROTECTED]>\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: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] >To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] >To contact the list administrators, e-mail: [EMAIL PROTECTED] _ . Christian Dechery . . Gaita-L Owner / Web Developer . . http://www.webstyle.com.br . . http://www.tanamesa.com.br -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Re: A tricky one?
Try This approach: $msg = " I want to order: "; if(!empty($pizza)) { $msg .= $pizza."Pizza"; } if(!empty($chips)) { $msg .= $chips."Chips "; } if(!empth($hamburgers)) { $msg .= $hamburgers." Hamburgers"; } //Note: PHP has a one-line if statement, which slips my mind for the moment. You can use it, to minimize the code above. Nevetheless, the concept stays the same. /* Creates the example message "I want to order: 2 pizza 4 chips 1 hamburger " */ You can then send $msg as the message of the e-mail, or append it to some more text. __John Monfort_ _+---+_ P E P I E D E S I G N S www.pepiedesigns.com "The world is waiting, are you ready?" -+___+- On Tue, 20 Nov 2001, Matthew Luchak wrote: > > try &&($val!="") instead of &&(isset($var) > > Matthew Luchak > Webmaster > Kaydara Inc. > [EMAIL PROTECTED] > > > -Original Message- > From: Raymond Lilleodegard [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, November 20, 2001 3:52 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] Re: A tricky one? > > > It works after modifying it a little. BUT... :) It lists all the > variables > even if they aren't given any value. Is it possible to only get the > defined > ones? > > Regards Raymond > > > "Matthew Luchak" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > how about... > > > $message=""; > $header="From: $email"; > $to="[EMAIL PROTECTED]"; > $subject="burger me"; > > while(list($var, $val) = each($HTTP_POST_VARS)) > { > if(($var !="email")&&($var !="SUBMIT")&&(isset($var)){$message > .="$val $var were ordered \n";} > } > > MAIL( > "$to", > "$subject", > "$message", > "$header" > ); > ?> > > Matthew Luchak > Webmaster > Kaydara Inc. > [EMAIL PROTECTED] > > > -Original Message- > From: Raymond Lilleodegard [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, November 20, 2001 1:57 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Re: A tricky one? > > > 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" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > 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 : ) > > > > > > > > > > > > > > > > script > > > /* recipients */ > > $to = "[EMAIL PROTECTED]" ; > > > > /* 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 <[EMAIL PROTECTED]>\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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: A tricky one?
Thank you very much guys! You really helped out with this one. I will sleep a lot better to night : ) Regards Raymond "Matthew Luchak" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... try &&($val!="") instead of &&(isset($var) Matthew Luchak Webmaster Kaydara Inc. [EMAIL PROTECTED] -Original Message- From: Raymond Lilleodegard [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 20, 2001 3:52 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Re: A tricky one? It works after modifying it a little. BUT... :) It lists all the variables even if they aren't given any value. Is it possible to only get the defined ones? Regards Raymond "Matthew Luchak" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... how about... Matthew Luchak Webmaster Kaydara Inc. [EMAIL PROTECTED] -Original Message- From: Raymond Lilleodegard [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 20, 2001 1:57 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: A tricky one? 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" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > 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 : ) > > > > > > > > script > /* recipients */ > $to = "[EMAIL PROTECTED]" ; > > /* 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 <[EMAIL PROTECTED]>\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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: A tricky one?
If you only want to show the ones variables that have values input by the user, you could do this with the while loop: while (list($var, $val) = each($HTTP_POST_VARS)) { if ((strlen($val) > 0) && ($var !="email") && ($var !="SUBMIT") && (isset($var)) { $message .= "$val $var were ordered \n"; } } This will make sure that the string length of $val (the value of the form element) is greater than 0; if not, it won't add it to the message. Joshua Hoover > It works after modifying it a little. BUT... :) It lists all the > variables > even if they aren't given any value. Is it possible to only get the > defined > ones? > > Regards Raymond > > > "Matthew Luchak" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > how about... > > > $message=""; > $header="From: $email"; > $to="[EMAIL PROTECTED]"; > $subject="burger me"; > > while(list($var, $val) = each($HTTP_POST_VARS)) > { > if(($var !="email")&&($var !="SUBMIT")&&(isset($var)){$message > .="$val $var were ordered \n";} > } > > MAIL( > "$to", > "$subject", > "$message", > "$header" > ); > ?> > > Matthew Luchak > Webmaster > Kaydara Inc. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Re: A tricky one?
try &&($val!="") instead of &&(isset($var) Matthew Luchak Webmaster Kaydara Inc. [EMAIL PROTECTED] -Original Message- From: Raymond Lilleodegard [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 20, 2001 3:52 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Re: A tricky one? It works after modifying it a little. BUT... :) It lists all the variables even if they aren't given any value. Is it possible to only get the defined ones? Regards Raymond "Matthew Luchak" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... how about... Matthew Luchak Webmaster Kaydara Inc. [EMAIL PROTECTED] -Original Message- From: Raymond Lilleodegard [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 20, 2001 1:57 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: A tricky one? 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" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > 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 : ) > > > > > > > > script > /* recipients */ > $to = "[EMAIL PROTECTED]" ; > > /* 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 <[EMAIL PROTECTED]>\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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: A tricky one?
It works after modifying it a little. BUT... :) It lists all the variables even if they aren't given any value. Is it possible to only get the defined ones? Regards Raymond "Matthew Luchak" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... how about... Matthew Luchak Webmaster Kaydara Inc. [EMAIL PROTECTED] -Original Message- From: Raymond Lilleodegard [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 20, 2001 1:57 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: A tricky one? 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" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > 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 : ) > > > > > > > > script > /* recipients */ > $to = "[EMAIL PROTECTED]" ; > > /* 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 <[EMAIL PROTECTED]>\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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Re: A tricky one?
how about... Matthew Luchak Webmaster Kaydara Inc. [EMAIL PROTECTED] -Original Message- From: Raymond Lilleodegard [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 20, 2001 1:57 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: A tricky one? 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" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > 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 : ) > > > > > > > > script > /* recipients */ > $to = "[EMAIL PROTECTED]" ; > > /* 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 <[EMAIL PROTECTED]>\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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]