Ejemplo n.º 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_gender, $id)
    {
        $sql = "UPDATE tbl_product SET `product_gender` = ? 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_gender, $id);
            $stmt->execute();
        }
        $stmt->close();
    }
}
if (isset($_POST['btn-product-detail']) && $_POST["btn-product-detail"] == 'Save Changes') {
    $_collection = new CONTROL_GENDER();
    $product = $_collection->get_product_id_color();
    $collection = filter_var($_POST['gender'], FILTER_SANITIZE_NUMBER_INT);
    $_collection->update_product($collection, $data['product_id']);
}
Ejemplo n.º 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_gender, $id)
    {
        $sql = "UPDATE tbl_product SET `product_gender` = ? 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_gender, $id);
            $stmt->execute();
        }
        $stmt->close();
    }
}
if (isset($_POST['add-product'])) {
    $_collection = new CONTROL_GENDER();
    $product = $_collection->get_product_id_color();
    $product_gender = filter_var($_POST['gender'], FILTER_SANITIZE_NUMBER_INT);
    $_collection->update_product($product_gender, $product->product_id);
}