Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Newbe HELP!

Simple calculation

7:13 am on Mar 7, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 21, 2003
votes: 0

I have a shopping cart that can pass variables to a script of my choice. I have a script which I have made from two. One passes data to a database and the other sends email. The reason I want to set this up is because eventually I want to run my whole site dynamically and the shopping cart won't calculate percentages and fees based on different payment options. I would like to know how to modify this to set new variables for the payment options that the cart returns to the script, like if payment option ==a then set $new variable $a= 2% of $total and if option ==b then $new variable $b= 15. Now set new variable $adjusted total=$total+$a+$b.
To make this work perfectly I would like to have a conditional paragraph in the email body depending on which payment option.
I have spent hours and hours trying different methods but I know very little about PHP code. Any help would be greatly appreciated.
I also need to add a cc email to myself.
Here's the code that I have working:


// Change to your email address
$MFrom = "orders@mydomain.com.au";

// The customer's email address is an incomming field
$MTo = $email;

// The Subject line
$MailSubject = "Customer order confirmation";

// Replace the cart's ~ delimiter with a new line \n
$cart = str_replace("~","\n",$cart);

// And this is the actual email and the function to send it
// In php(and Perl) a field name has a $ sign in front of it
// the rest is just free text
Thank you for your order.

Username : $username
Customer ID : $id
Date : $date
For payment by $method

Product , Quantity , Price

Discount : -$discount
Subtotal : $subtotal
Shipping : $shipping
Tax : $tax
TOTAL : $total

Invoice To:

Ship To:

If you have any questions about your order please do not hesitate
to contact us.

","From: " . $MFrom);

// Plus you have this field $ip which is their IP address and the $message fields

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database $DBName");

mysql_select_db($DBName) or die("Unable to select database $DBName");

$order_date=date("j F, Y, g:i a(T)");

mysql_query("REPLACE INTO orders (username,id,ip, date,method,cart,discount,subtotal,shipping,tax,total, ccc,tt,adjusted_total,shipping_zone,inv_name, inv_company,inv_addr1,inv_addr2,inv_state,inv_zip, inv_country,del_name,del_addr1,del_addr2,del_state, del_zip,del_country,tel,fax,email,message)
VALUES ('$username',$id,'$ip','$order_date', '$method','$cart','$discount','$subtotal', '$shipping','$tax','$total','$ccc,'$tt', '$adjusted_total',$shipping_zone,'$inv_name', '$inv_company','$inv_addr1','$inv_addr2','$inv_state', '$inv_zip','$inv_country','$del_name','$del_addr1', '$del_addr2','$del_state','$del_zip','$del_country', '$tel','$fax','$email','$message')");



[edited by: ergophobe at 9:02 am (utc) on Mar. 7, 2005]
[edit reason] fixed sidescroll [/edit]


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members