User talk:NoSeptember/Main

php
<?php $conn = mysqli_connect("localhost", "root", "afthab", "library");

// Insert record if (isset($_POST['insert'])) { $book_id = $_POST['book_id']; $title = $_POST['title']; $author = $_POST['author']; $publisher = $_POST['publisher']; $year = $_POST['year'];

$sql = "INSERT INTO book (book_id, title, author, publisher, year) VALUES ('$book_id', '$title', '$author', '$publisher', '$year')"; $data = mysqli_query($conn, $sql);

if ($data) { echo "One record is inserted"; } else { echo "No record is inserted"; } }

// Update record if (isset($_POST['update'])) { $book_id = $_POST['book_id']; $title = $_POST['title']; $author = $_POST['author']; $publisher = $_POST['publisher']; $year = $_POST['year'];

$sql = "UPDATE book SET title='$title', author='$author', publisher='$publisher', year='$year' WHERE book_id='$book_id'"; $data = mysqli_query($conn, $sql);

if ($data) { echo "One record is updated"; } else { echo "No record is updated"; } }

// Delete record if (isset($_POST['delete'])) { $book_id = $_POST['book_id'];

$sql = "DELETE FROM book WHERE book_id='$book_id'"; $data = mysqli_query($conn, $sql);

if ($data) { echo "One record is deleted"; } else { echo "No record is deleted"; } }

// Display records $sql = "SELECT * FROM book"; $result = $conn->query($sql); $conn->close; ?>

<!DOCTYPE html> Book Management  Insert New Book  Book ID:  Title:  Author:  Publisher:  Year:  

Update Book  Book ID:  Title:  Author:  Publisher:  Year:  

Delete Book  Book ID: <input type="number" name="book_id" required> <input class="button" type="submit" name="delete" value="Delete">

Display Books <?php if ($result->num_rows > 0) { echo " "; } else { echo "0 results"; }   ?> Rauof9292 (talk) 12:38, 10 July 2024 (UTC)