Example #1
0
    private $conn;
    function __construct()
    {
        $this->conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    }
    function get_product_id_color()
    {
        $sql = "SELECT MAX(id) as product_id FROM tbl_product";
        $query = $this->conn->query($sql);
        $result = $query->fetch_object();
        return $result;
    }
    function update_product($product_collection, $id)
    {
        $sql = "UPDATE tbl_product SET `product_collection` = ? WHERE `id` = ?";
        $stmt = $this->conn->prepare($sql);
        if ($stmt === false) {
            trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR);
        } else {
            $stmt->bind_param("ss", $product_collection, $id);
            $stmt->execute();
        }
        $stmt->close();
    }
}
if (isset($_POST['btn-product-detail']) && $_POST["btn-product-detail"] == 'Save Changes') {
    $_collection = new CONTROL_COLLECTION();
    $product = $_collection->get_product_id_color();
    $collection = filter_var($_POST['collection'], FILTER_SANITIZE_NUMBER_INT);
    $_collection->update_product($collection, $data['product_id']);
}
Example #2
0
    private $conn;
    function __construct()
    {
        $this->conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    }
    function get_product_id_color()
    {
        $sql = "SELECT MAX(id) as product_id FROM tbl_product";
        $query = $this->conn->query($sql);
        $result = $query->fetch_object();
        return $result;
    }
    function update_product($product_collection, $id)
    {
        $sql = "UPDATE tbl_product SET `product_collection` = ? WHERE `id` = ?";
        $stmt = $this->conn->prepare($sql);
        if ($stmt === false) {
            trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR);
        } else {
            $stmt->bind_param("ss", $product_collection, $id);
            $stmt->execute();
        }
        $stmt->close();
    }
}
if (isset($_POST['add-product'])) {
    $_collection = new CONTROL_COLLECTION();
    $product = $_collection->get_product_id_color();
    $collection = filter_var($_POST['collection'], FILTER_SANITIZE_NUMBER_INT);
    $_collection->update_product($collection, $product->product_id);
}