Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = 'localhost';
- $db = 'books';
- $user = 'root';
- $pass = 'password';
- $con = mysqli_connect($host, $user, $pass, $db);
- if ($con) {
- echo 'Successfully connected to database!';
- } else{
- die('Did not connect');
- }
- ?>
- <?php
- include_once 'sqlConnect.php';
- ?>
- <!doctype html>
- <html lang="en">
- <head>
- <title> Library Catalog </title>
- </head>
- <style>
- h1 {
- color: #08298A;
- }
- </style>
- <body>
- <h1> <center> Library Catalog </center> </h1>
- <h4> <center> Add a New Book </center> </h4>
- <center>
- <form method="POST">
- <input type="text" name="title" placeholder="Title" id="title">
- <input type="text" name="author" placeholder="Author" id="author">
- <input type="text" name="genre" placeholder="Genre" id="genre">
- <input type="text" name="quantity" placeholder="Quantity" id="quantity">
- <input type="submit" name="submit" value="Submit"/>
- <!-- <button type="submit" name="submit"> Submit</button> -->
- </form>
- </center>
- <?php
- $title = $_POST['title'];
- $author = $_POST['author'];
- $genre = $_POST['genre'];
- $quantity = (int)$_POST['quantity'];
- $submit = $_POST['submit'];
- if ($submit) {
- $sql = "INSERT INTO catalog (id, title, author, genre, quantity) VALUES (NULL, '$title', '$author', '$genre', '10');";
- mysqli_query($con, $sql);
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment