Forum Moderators: coopster
<?php
$orderid = Trim(stripslashes($_POST['ordernumber']));
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'psw';
$dbname = 'store';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$conn) {
die('Failed to connect to server: ' . mysql_error());
}
mysql_select_db($dbname);
$sql="SELECT * FROM orders_products WHERE orders_id = '".$orderid."'";
$result = mysql_query($sql);
$firstname = Trim(stripslashes($_POST['firstname']));
$lastname = Trim(stripslashes($_POST['lastname']));
$email = Trim(stripslashes($_POST['email']));
$mtcn = Trim(stripslashes($_POST['mtcn']));
$amount = Trim(stripslashes($_POST['amount']));
$country = Trim(stripslashes($_POST['country']));
$ordernumber = Trim(stripslashes($_POST['ordernumber']));
$currency = Trim(stripslashes($_POST['currency']));
$emailto = "to@email.com";
$emailcc = "cc@email.com";
$subject = "Information - Order No:";
$headers = "From: $email" . "\r\n" . "CC: $emailcc";
// prepare email body text
$body .= "--------------------------------------\n";
$body .= "Details\n";
$body .= "--------------------------------------\n";
$body .= "First name: ";
$body .= $firstname;
$body .= "\n";
$body .= "Last name: ";
$body .= $lastname;
$body .= "\n";
$body .= "Email Address: ";
$body .= $email;
$body .= "\n\n";
$body .= "--------------------------------------\n";
$body .= "Products\n";
$body .= "--------------------------------------\n";
while($row=mysql_fetch_array($result)) {
$body .= $row['products_quantity']." x ".$row['products_name']." = ".sprintf("%.2f", ($row['products_quantity'] * $row['final_price'])) . "\n";
}
$body .= "\n";
$body .= "--------------------------------------\n";
$body .= "Delivery Address\n";
$body .= "--------------------------------------\n";
$body .= "Delivery Name:: ";
$body .= $row2['delivery_name'];
$body .= "\n";
$body .= "Address 1:: ";
$body .= $row2['delivery_street_address'];
$body .= "\n";
$body .= "Address 2: ";
$body .= $row2['delivery_suburb'];
$body .= "\n";
$body .= "Address 3: ";
$body .= $row2['delivery_city'];
$body .= "\n";
$body .= "Postcode: ";
$body .= $row2['delivery_postcode'];
$body .= "\n";
$body .= "Country: ";
$body .= $row2['delivery_country'];
$body .= "\n";
// send email
$send = mail($emailto, $subject . ' ' . $ordernumber, $body, $headers);
mysql_close($conn);
// redirect to success page
if ($send){
print "<meta http-equiv=\"refresh\" content=\"0;URL=sent.php\">";
}
else{
print "We encountered an error sending your mail";
}
?>
I'm sure you'll notice that row2 isn't defined anywhere
$orderitems=$body=null;
$query = "select the base order data and get order_id";
$result = mysql_query($result) or die("cannot get base order data");
//
if ($row=mysql_fetch_array($result)) { // use IF, there is only ONE
//
$query = "select the ordered items where order_id=$your_order_id"; // OK to recycle, we're done with it
$result2 = mysql_query($query) or die("cannot get the order items");
while ($row2=mysql_fetch_array($result2)) {
$orderitems .= "Concatentate order item rows here using *$row2* data";
}
$body .= "Add your shipping and base order data here";
if ($orderitems) { $body .= $orderitems; }
// Error trapping is your friend!
else { $body .= "Hmm, no order items"; }
}
else { $body .= "Hmm, no order was found"; }
<?php
$orderid = Trim(stripslashes($_POST['ordernumber']));
$dbhost = 'localhost';
$dbuser = 'dbadmin';
$dbpass = 'psw';
$dbname = 'store';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$conn) {
die('Failed to connect to server: ' . mysql_error());
}
mysql_select_db($dbname);
$sql="SELECT * FROM orders_products WHERE orders_id = '".$orderid."'";
$result = mysql_query($sql)or die("Cannot query orders_products data" . mysql_error());
$sql2="SELECT * FROM orders WHERE orders_id = '".$orderid."'";
$result2 = mysql_query($sql2) or die("Cannot query orders data" . mysql_error());
$firstname = Trim(stripslashes($_POST['firstname']));
$lastname = Trim(stripslashes($_POST['lastname']));
$email = Trim(stripslashes($_POST['email']));
$ordernumber = Trim(stripslashes($_POST['ordernumber']));
$emailto = "to@email.com";
$emailcc = "cc@email.com";
$subject = "Information - Order No:";
$headers = "From: $email" . "\r\n" . "CC: $emailcc";
// prepare email body text
$body .= "--------------------------------------\n";
$body .= "Details\n";
$body .= "--------------------------------------\n";
$body .= "First name: $firstname" . "\n";
$body .= "Last name: $lastname" . "\n";
$body .= "Email: $email" . "\n";
$body .= "\n--------------------------------------\n";
$body .= "Products";
$body .= "\n--------------------------------------\n";
while($row=mysql_fetch_array($result)) {
$body .= $row['products_quantity']." x ".$row['products_name']." = ".sprintf("%.2f", ($row['products_quantity'] * $row['final_price'])) . "\n";
}
while($row2=mysql_fetch_array($result2)) {
$body .= "\n--------------------------------------\n";
$body .= "Delivery Address";
$body .= "\n--------------------------------------\n";
$body .= ucwords($row2['delivery_name']) . "\n";
$body .= ucwords($row2['delivery_street_address']) ."\n";
if($row2['delivery_suburb']) {
$body .= ucwords($row2['delivery_suburb']) . "\n";
}
if($row2['delivery_city']) {
$body .= $row2['delivery_city'] . "\n";
}
$body .= strtoupper($row2['delivery_postcode']) . "\n";
$body .= $row2['delivery_country'] . "\n";
}
// send email
$send = mail($emailto, $subject . ' ' . $ordernumber, $body, $headers);
mysql_close($conn);
// redirect to success page
if ($send){
print "<meta http-equiv=\"refresh\" content=\"0;URL=sent.php\">";
}
else{
print "We encountered an error sending your mail.";
}
?>
prehaps only selecting required fields?