create
dùng để hiển thị Form cho người dùng nhập liệu/backend/functions/loaisanpham/create.php
để hiển thị form cho người dùng nhập liệu và xử lý INSERT vào database<!-- Nhúng file cấu hình để xác định được Tên và Tiêu đề của trang hiện tại người dùng đang truy cập --> <?php include_once(__DIR__ . '/../../layouts/config.php'); ?> <!DOCTYPE html> <html> <head> <!-- Nhúng file quản lý phần HEAD --> <?php include_once(__DIR__ . '/../../layouts/head.php'); ?> </head> <body class="d-flex flex-column h-100"> <!-- header --> <?php include_once(__DIR__ . '/../../layouts/partials/header.php'); ?> <!-- end header --> <div class="container-fluid"> <div class="row"> <!-- sidebar --> <?php include_once(__DIR__ . '/../../layouts/partials/sidebar.php'); ?> <!-- end sidebar --> <main role="main" class="col-md-10 ml-sm-auto px-4 mb-2"> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> <h1 class="h2">Thêm mới Loại sản phẩm</h1> </div> <!-- Block content --> <form name="frmLoaiSanPham" id="frmLoaiSanPham" method="post" action=""> <div class="form-group"> <label for="id">ID loại sản phẩm</label> <input type="text" class="form-control" id="id" name="id" placeholder="ID loại sản phẩm" readonly> <small id="idHelp" class="form-text text-muted">ID loại sản phẩm không được hiệu chỉnh.</small> </div> <div class="form-group"> <label for="category_code">Mã loại sản phẩm</label> <input type="text" class="form-control" id="category_code" name="category_code" placeholder="Mã loại sản phẩm" value=""> </div> <div class="form-group"> <label for="category_name">Tên loại sản phẩm</label> <input type="text" class="form-control" id="category_name" name="category_name" placeholder="Tên loại sản phẩm" value=""> </div> <div class="form-group"> <label for="description">Mô tả loại sản phẩm</label> <textarea class="form-control" id="description" name="description" placeholder="Mô tả loại sản phẩm"></textarea> </div> <button class="btn btn-primary" name="btnSave">Lưu dữ liệu</button> </form> <!-- End block content --> </main> </div> </div> <!-- footer --> <?php include_once(__DIR__ . '/../../layouts/partials/footer.php'); ?> <!-- end footer --> <!-- Nhúng file quản lý phần SCRIPT JAVASCRIPT --> <?php include_once(__DIR__ . '/../../layouts/scripts.php'); ?> <!-- Các file Javascript sử dụng riêng cho trang này, liên kết tại đây --> <!-- <script src="..."></script> --> </body> </html>
<!-- Nhúng file cấu hình để xác định được Tên và Tiêu đề của trang hiện tại người dùng đang truy cập --> <?php include_once(__DIR__ . '/../../layouts/config.php'); ?> <!DOCTYPE html> <html> <head> <!-- Nhúng file quản lý phần HEAD --> <?php include_once(__DIR__ . '/../../layouts/head.php'); ?> </head> <body class="d-flex flex-column h-100"> <!-- header --> <?php include_once(__DIR__ . '/../../layouts/partials/header.php'); ?> <!-- end header --> <div class="container-fluid"> <div class="row"> <!-- sidebar --> <?php include_once(__DIR__ . '/../../layouts/partials/sidebar.php'); ?> <!-- end sidebar --> <main role="main" class="col-md-10 ml-sm-auto px-4 mb-2"> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> <h1 class="h2">Thêm mới Loại sản phẩm</h1> </div> <!-- Block content --> <form name="frmLoaiSanPham" id="frmLoaiSanPham" method="post" action=""> <div class="form-group"> <label for="lsp_ma">Mã loại sản phẩm</label> <input type="text" class="form-control" id="lsp_ma" name="lsp_ma" placeholder="Mã loại sản phẩm" readonly> <small id="idHelp" class="form-text text-muted">Mã loại sản phẩm không được hiệu chỉnh.</small> </div> <div class="form-group"> <label for="lsp_ten">Tên loại sản phẩm</label> <input type="text" class="form-control" id="lsp_ten" name="lsp_ten" placeholder="Tên loại sản phẩm" value=""> </div> <div class="form-group"> <label for="lsp_mota">Mô tả loại sản phẩm</label> <textarea class="form-control" id="lsp_mota" name="lsp_mota" placeholder="Mô tả loại sản phẩm"></textarea> </div> <button class="btn btn-primary" name="btnSave">Lưu dữ liệu</button> </form> <?php // Truy vấn database // 1. Include file cấu hình kết nối đến database, khởi tạo kết nối $conn include_once(__DIR__ . '/../../../dbconnect.php'); // 2. Nếu người dùng có bấm nút "Lưu dữ liệu" if (isset($_POST['btnSave'])) { // Lấy dữ liệu người dùng hiệu chỉnh gởi từ REQUEST POST $lsp_ten = $_POST['lsp_ten']; $lsp_mota = $_POST['lsp_mota']; // Thực thi câu lệnh SQL QUERY // Câu lệnh INSERT $sql = "INSERT INTO `loaisanpham` (lsp_ten, lsp_mota) VALUES ('$lsp_ten', '$lsp_mota');"; // Thực thi INSERT mysqli_query($conn, $sql) or die("<b>Có lỗi khi thực thi câu lệnh SQL: </b>" . mysqli_error($conn) . "<br /><b>Câu lệnh vừa thực thi:</b></br>$sql"); // Đóng kết nối mysqli_close($conn); // Sau khi cập nhật dữ liệu, tự động điều hướng về trang Danh sách // Điều hướng bằng Javascript echo '<script>location.href = "index.php";</script>'; } ?> <!-- End block content --> </main> </div> </div> <!-- footer --> <?php include_once(__DIR__ . '/../../layouts/partials/footer.php'); ?> <!-- end footer --> <!-- Nhúng file quản lý phần SCRIPT JAVASCRIPT --> <?php include_once(__DIR__ . '/../../layouts/scripts.php'); ?> <!-- Các file Javascript sử dụng riêng cho trang này, liên kết tại đây --> <!-- <script src="..."></script> --> </body> </html>
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!