Advertisement
zihadrizkyef

get_product_details.php

Sep 3rd, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2.  
  3.     $response = array();
  4.  
  5.     require_once __DIR__ . '/db_connect.php';
  6.  
  7.     $db = new DB_CONNECT();
  8.  
  9.     if (isset($_GET['pid'])) {
  10.         $pid = $_GET['pid'];
  11.         $result = msql_query("SELECT * FROM products WHERE pid = $pid");
  12.  
  13.         if (!empty($result)) {
  14.             if (mysql_num_rows($result)>0) {
  15.                 $result = msql_fetch_array($result);
  16.  
  17.                 $products = array();
  18.                 $products['pid'] = $result['pid'];
  19.                 $products['name'] = $result['name'];
  20.                 $products['price'] = $result['price'];
  21.                 $products['description'] = $result['description'];
  22.                 $products['created_at'] = $result['created_at'];
  23.                 $products['updated_at'] = $result['updated_at'];
  24.  
  25.                 $response['success'] = 1;
  26.                 $response['product'] = array();
  27.                 array_push($response['product'], $products);
  28.             } else {
  29.                 $response['success'] = 0;
  30.                 $response['message'] = "No product found";
  31.             }
  32.         } else {
  33.             $response['success'] = 0;
  34.             $response['message'] = "No product found";
  35.         }
  36.     } else {
  37.         $response['success'] = 0;
  38.         $response['message'] = "Required field(s) is missing";
  39.     }
  40.  
  41.     echo json_encode($response);
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement