Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Function to Add Product **/
- function add_product() {
- $data = json_decode(file_get_contents("php://input"));
- $prod_name = $data->prod_name;
- $prod_desc = $data->prod_desc;
- $prod_price = $data->prod_price;
- $prod_quantity = $data->prod_quantity;
- print_r($data);
- $qry = 'INSERT INTO product (prod_name,prod_desc,prod_price,prod_quantity) values ("' . $prod_name . '","' . $prod_desc . '",' .$prod_price . ','.$prod_quantity.')';
- $qry_res = mysql_query($qry);
- if ($qry_res) {
- $arr = array('msg' => "Product Added Successfully!!!", 'error' => '');
- $jsn = json_encode($arr);
- // print_r($jsn);
- }
- else {
- $arr = array('msg' => "", 'error' => 'Error In inserting record');
- $jsn = json_encode($arr);
- // print_r($jsn);
- }
- }
- /** Function to Get Product **/
- function get_product() {
- $qry = mysql_query('SELECT * from product');
- $data = array();
- while($rows = mysql_fetch_array($qry))
- {
- $data[] = array(
- "id" => $rows['id'],
- "prod_name" => $rows['prod_name'],
- "prod_desc" => $rows['prod_desc'],
- "prod_price" => $rows['prod_price'],
- "prod_quantity" => $rows['prod_quantity']
- );
- }
- print_r(json_encode($data));
- return json_encode($data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement