Page 29 - 3-2
P. 29

----------------*create_product.php*-------------
            <?php
            /*
             * Following code will create a new product row
             * All product details are read from HTTP Post Request
             */
            // array for JSON response
            $response = array();
            // include db connect class
                require_once __DIR__ . '/db_connect.php';


            if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['code'])) {
                $code = $_POST['code']
                $name = $_POST['name'];
                $price = $_POST['price'];
             //  $description = $_POST['description'];
                // connecting to db
                // $db = new DB_CONNECT();


                // mysql inserting a new row
                $result    =    mysqli_query($con,"INSERT       INTO     mdp_manu(code,       name,     price)
            VALUES('$code','$name', '$price')");


                // check if row inserted or not
                if ($result) {
                    // successfully inserted into database
                    $response["success"] = 1;
                    $response["message"] = "Product successfully created.";


                    // echoing JSON response
                    echo json_encode($response);
                } else {
                    // failed to insert row
                    $response["success"] = 0;
                    $response["message"] = "Oops! An error occurred.";


                    // echoing JSON response
                    echo json_encode($response);
                }
            } else {
                // required field is missing
                $response["success"] = 0;
                $response["message"] = "Required field(s) is missing";


                // echoing JSON response


                                                         - 29 -
   24   25   26   27   28   29   30   31   32   33   34