vdp

Untitled

vdp
Jul 31st, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.83 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4. include("../includes/db.php");
  5. include("../functions/functions.php");
  6.  
  7. //retrieving customer id that was passed from payment page
  8. if(isset($_GET['c_id'])){
  9.  
  10.     $customer_id=$_GET['c_id']; //local variable to save a customer id
  11.     $c_email ="select * from customers WHERE customer_id='$customer_id'";
  12.     //sending email
  13.     $run_email=mysqli_query($con,$c_email);
  14.     $row_customer=mysqli_fetch_array($run_email);
  15.     $customer_email=$row_customer['customer_email'];
  16.     $customer_name=$row_customer['customer_name'];
  17.  
  18.  
  19.  
  20. }
  21. //getting products information/no. of items from cart
  22.  
  23. $ip_add = getRealIpAddress();
  24.  
  25.  
  26.  
  27. $total =0;
  28.  
  29.  
  30. $select_price = "select * from cart where ip_add = '$ip_add'";
  31.  
  32. $run_price = mysqli_query($db, $select_price);
  33.  
  34.     $status='Pending';//initial status of a product
  35.  
  36.     $invoice_no = mt_rand();//generate random number
  37.  
  38.     $count_pro=mysqli_num_rows($run_price); //total products
  39.  
  40.     $i=0;
  41.  
  42.     $message="
  43.  
  44.     <html>
  45.     <body>
  46.     <p>
  47.  
  48.     Hello  <b style='color:blue;'> $customer_name, </b> <br>
  49.  
  50.     Please find your order summary bellow. Please login to your account and make a payment for any pending orders. </p>
  51.  
  52.     <table width='600' align='center' bgcolor='FFCC99' border='2'>
  53.     <tr> <h2> Your Order Summary.<br>
  54.     Invoice Number: $invoice_no </br></h2></tr>
  55.     <tr>
  56.  
  57.  
  58.     <th> Product Name </b> </th>
  59.     <th> Quantity </b> </th>
  60.     <th> Total Price </b> </th>
  61.  
  62.     </tr>
  63.  
  64.  
  65.     ";
  66.  
  67.  
  68.     while($record=mysqli_fetch_array($run_price))
  69.     {
  70.         $product_id = $record['p_id'];
  71.         $prod_price = "select * from products where product_id = '$product_id'";
  72.  
  73.         $run_product_price = mysqli_query($db, $prod_price);
  74.  
  75.         while($p_price=mysqli_fetch_array($run_product_price))
  76.         {
  77.             $product_name=$p_price['product_title'];
  78.             $product_price = array($p_price['product_price']); //get product price from table column in DB
  79.             $value = array_sum($product_price); // sum all the values
  80.             $total += $value;
  81.             $i++;
  82.  
  83.         }
  84.         $message.="
  85.  
  86.  
  87.  
  88.         <tr>
  89.         <td> $product_name </td>";
  90.  
  91.  
  92.     //end of while
  93.     //getting quantity form the cart
  94.         $get_cart ="Select * from cart WHERE ip_add = '$ip_add'";
  95.         $run_cart=mysqli_query($con,$get_cart);
  96.         $get_qty= mysqli_fetch_array($run_cart);
  97.  
  98.     $qty=$get_qty['qty']; //saving qty from database to local variable
  99.  
  100.     if($qty==0)
  101.     {
  102.         //change the variable
  103.         $qty=1;
  104.         $sub_total =$total;
  105.     }
  106.     else
  107.     {
  108.         $qty=$qty;
  109.         $sub_total=$total*$qty;
  110.     }
  111.  
  112.  
  113.     //if($run_order)
  114.     //{
  115.  
  116.     echo "<script>window.open('my_account.php','_self')</script>";
  117.         $empty_cart="delete from cart where ip_add='$ip_add'"; //empty the cart once the order has been submitted
  118.  
  119.         $run_empty=mysqli_query($con,$empty_cart);
  120.  
  121.         $insert_to_pending_order="insert into pending_orders(customer_id,invoice_no,product_id,qty,order_status) values('$customer_id','$invoice_no','$product_id','$qty','$status')";
  122.         $run_pending_order=mysqli_query($con,$insert_to_pending_order);
  123.  
  124.  
  125.         $message.="<td> $qty </td>
  126.         <td> #$value </td>
  127.  
  128.         </tr>";
  129.  
  130.  
  131.     }
  132.  
  133.     $message.="
  134.     <tr>
  135.     <td> YOUR SUBTOTAL IS # $sub_total </td>
  136.     </tr></table>
  137.  
  138.     <h3> Thank you for your order </h3>
  139.     </body>
  140.  
  141.     </html>
  142.  
  143.  
  144.     ";
  145.  
  146.  
  147.  
  148.     //SENDING INVOICE TO CUSTOMER
  149.  
  150.  
  151.  
  152. //}
  153.     $insert_order="insert into customer_orders(customer_id,due_amount,invoice_no,total_products,order_date,order_status) values('$customer_id','$sub_total','$invoice_no','$count_pro',NOW(),'$status')";
  154.     $run_order = mysqli_query($con,$insert_order);
  155.     echo "<script>alert('Order details sent!! $message') </script>";
  156.     $subject = 'Your Order Details';
  157.  
  158. // To send HTML mail, the Content-type header must be set
  159.     $headers  = 'MIME-Version: 1.0' . "\r\n";
  160.     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  161.  
  162. // Additional headers
  163.     $headers .= 'To: echo $customer_email'. "\r\n";
  164.     $headers .= 'From: admin@kshop.com';
  165.  
  166. // Mail it
  167.     mail($customer_email, $subject, $message, $headers);
  168.  
  169.  
  170.  
  171.     ?>
Add Comment
Please, Sign In to add comment