Các bước thực hiện:
Tạo size insert tài liệu.Kết nối database với table.Lấy dữ liệu post từ bỏ formXử lý dữ liệu.Đóng database.Form dữ liệuBạn đang xem: Code thêm sản phẩm trong php
post">
Xem thêm: ung thư tế bào hắc tố
// Knhì báo username$password = "123456"; // Khai báo password$hệ thống = "localhost"; // Khai báo server$dbname = "tintuc"; // Knhì báo database// Kết nối database tintuc$connect = new mysqli($server, $username, $password, $dbname);//Nếu liên kết bị lỗi thì xuất báo lỗi và thoát.if ($connect->connect_error) die("Không kết nối :" . $conn->connect_error); exit();//Knhị làm giá trị thuở đầu, nếu không có thì Khi chưa submit câu lệnh insert vẫn báo lỗi$title = "";$date = "";$description = "";$nội dung = "";//Lấy cực hiếm POST từ size vừa submitif ($_SERVER<"REQUEST_METHOD"> == "POST") if(isset($_POST<"title">)) $title = $_POST<'title'>; if(isset($_POST<"date">)) $date = $_POST<'date'>; if(isset($_POST<"description">)) $mô tả tìm kiếm = $_POST<'description'>; if(isset($_POST<"content">)) $content = $_POST<'content'>; //Code xử lý, insert tài liệu vào table $sql = "INSERT INTO tin_xahoi (title, date, description, content) VALUES ('$title', '$date', '$description', '$content')"; if ($connect->query($sql) === TRUE) emang lại "Thêm tài liệu thành công"; else emang lại "Error: " . $sql . "" . $connect->error; //Đóng database$connect->close();?>Trong file download đã bao gồm sẵn tệp tin tintuc.sql, tệp tin này là file dữ liệu chủng loại, sau thời điểm đã tạo thành database bạn cũng có thể gửi dữ liệu tự file tintuc.sql bởi làm việc import bao gồm vào phpMyAdmin.