homepage Welcome to WebmasterWorld Guest from 54.227.12.4
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Newbe HELP!
Simple calculation
gruntre




msg:1268156
 7:13 am on Mar 7, 2005 (gmt 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:

<?PHP
include("config.php");

// 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
mail($MTo,$MailSubject,"
Thank you for your order.

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

Product , Quantity , Price
==========================
$cart

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

Invoice To:
$inv_name
$inv_compay
$inv_addr1
$inv_addr2
$inv_state
$inv_zip
$inv_country
$tel
$fax
$email

Ship To:
$del_name
$del_addr1
$del_addr2
$del_state
$del_zip
$del_country

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')");

?>

Success!

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

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved