Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. function make_order($post) {
  2.     global $dbh;
  3.    
  4.     if($post['delivery_type'] == 0) {
  5.        
  6.         $post['customer'] = json_encode( $post['customer'] );
  7.        
  8.         unset($post['receiver']);
  9.        
  10.     }
  11.    
  12.     if($post['delivery_type'] == 1) {
  13.        
  14.         $post['receiver'] = json_encode( $post['receiver'] );
  15.        
  16.         unset($post['customer']);
  17.        
  18.     }
  19.    
  20.     $post['user_id'] = $_SESSION['user']['id'];
  21.    
  22.     $post['goods'] = json_encode($_SESSION['cart']);
  23.    
  24.    
  25.     $values = implode("','", $post);
  26.     $keys = implode('`,`', array_keys($post));
  27.     $sql = "INSERT INTO orders (`{$keys}`) VALUES ('{$values}')";
  28.     $query = $dbh->query($sql);
  29.     if($query) {
  30.         $id = $dbh->lastInsertId();    
  31.      
  32.         send_email_order(['id'=>$id], $_SESSION['user']['id'], 'webiste');
  33.        
  34.        
  35.        
  36.        
  37.         return ['ok'=>true];
  38.     }
  39.  
  40.     return ['error'=>'Ошибка сохранения данных!', 'db_error'=>$dbh->errorInfo(), "sql"=>$sql];
  41.    
  42.    
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement