[thelist] emailing dynamically generated form results using php

sasha spam at bittersweet2.com
Tue Oct 22 09:44:01 CDT 2002


I hope this will help (arrays aren't my strong suit either).
This is what I wrote for a shopping cart for the purchaser's
email notification.  Not exactly the prettiest code, but it
worked for me.

$cart was my session variable containing an array where the
product id was the "key" of the quantity purchased.

foreach($cart as $id => $qty) {
	if (@$result = mysql_query("select * from products
where id = $id")) {
		$row = mysql_fetch_array($result);
		if ($qty != 0) {
			$purchase .= $qty . ' of ' . $row['name'] .
"\n";
			$subtotal += $row['price'] * $qty;
		}
	}
}

Once the product id was known, it could be pulled out of the
database and any portion of the product's information could
be used.  Then all you have to do is add the variable
$purchase to your email body.

sasha

10/22/2002 9:09:11 AM, "Dunstan Orchard" <dunstan@
1976design.com> wrote:

>Hi there,
>
>I have a checkout page which pulls a user's purchases from a
shopping cart
>mysql table and displays them prior to submission.
>
>The checkout page consists of input form elements for them
to enter their
>details, and a table below that where their choices are
rendered row by row
>along with input boxed for them to input the number of each
item they want to
>purchase.
>
>eg.
>
>-------------------------------
>Name: _________
>Email: _________
>Tel: _________
>
>
>Images:
>
>#13 Number of A4 prints: _________  Number of A3 prints:
_________
>#26 Number of A4 prints: _________  Number of A3 prints:
_________
>#74 Number of A4 prints: _________  Number of A3 prints:
_________
>
>SUBMIT
>-------------------------------
>
>
>This form is emailed to me on submission.
>
>What I'm stuck on is how do I write all their image choices
and the number of
>prints of these images to an email?
>
>If the choices were fixed then it wouldn't be a problem, but
the user could
>choose any of 1000 images to buy and any combination of
prints. How do I pass
>all their choices to the email script and write it in?
>
>Is it going to be an array?
>I don't know very much about arrays :o(
>
>thanks for any help you can offer - dunstan
>
>---------------------------
>Dorset, England
>http://www.1976design.com/
>http://www.orchard.it/
>http://www.maccaws.org/
>--
>For unsubscribe and other options, including
>the Tip Harvester and archive of thelist go to:
>http://lists.evolt.org Workers of the Web, evolt !
>






More information about the thelist mailing list