Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. /** Function to Add Product **/
  2.  
  3. function add_product() {
  4. $data = json_decode(file_get_contents("php://input"));
  5. $prod_name = $data->prod_name;
  6. $prod_desc = $data->prod_desc;
  7. $prod_price = $data->prod_price;
  8. $prod_quantity = $data->prod_quantity;
  9.  
  10. print_r($data);
  11.  
  12.  
  13. $qry = 'INSERT INTO product (prod_name,prod_desc,prod_price,prod_quantity) values ("' . $prod_name . '","' . $prod_desc . '",' .$prod_price . ','.$prod_quantity.')';
  14. $qry_res = mysql_query($qry);
  15. if ($qry_res) {
  16.  
  17. $arr = array('msg' => "Product Added Successfully!!!", 'error' => '');
  18. $jsn = json_encode($arr);
  19. // print_r($jsn);
  20. }
  21. else {
  22. $arr = array('msg' => "", 'error' => 'Error In inserting record');
  23. $jsn = json_encode($arr);
  24. // print_r($jsn);
  25. }
  26. }
  27.  
  28.  
  29. /** Function to Get Product **/
  30.  
  31. function get_product() {
  32. $qry = mysql_query('SELECT * from product');
  33. $data = array();
  34. while($rows = mysql_fetch_array($qry))
  35. {
  36. $data[] = array(
  37. "id" => $rows['id'],
  38. "prod_name" => $rows['prod_name'],
  39. "prod_desc" => $rows['prod_desc'],
  40. "prod_price" => $rows['prod_price'],
  41. "prod_quantity" => $rows['prod_quantity']
  42. );
  43. }
  44. print_r(json_encode($data));
  45. return json_encode($data);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement