Guest User

Untitled

a guest
Jan 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2.  
  3. $host = 'localhost';
  4. $db = 'books';
  5. $user = 'root';
  6. $pass = 'password';
  7.  
  8. $con = mysqli_connect($host, $user, $pass, $db);
  9.  
  10. if ($con) {
  11. echo 'Successfully connected to database!';
  12. } else{
  13. die('Did not connect');
  14. }
  15.  
  16. ?>
  17.  
  18. <?php
  19.  
  20. include_once 'sqlConnect.php';
  21.  
  22. ?>
  23.  
  24. <!doctype html>
  25. <html lang="en">
  26.  
  27. <head>
  28.  
  29. <title> Library Catalog </title>
  30.  
  31. </head>
  32.  
  33. <style>
  34.  
  35. h1 {
  36. color: #08298A;
  37. }
  38.  
  39. </style>
  40.  
  41. <body>
  42.  
  43. <h1> <center> Library Catalog </center> </h1>
  44.  
  45.  
  46. <h4> <center> Add a New Book </center> </h4>
  47.  
  48. <center>
  49. <form method="POST">
  50. <input type="text" name="title" placeholder="Title" id="title">
  51. <input type="text" name="author" placeholder="Author" id="author">
  52. <input type="text" name="genre" placeholder="Genre" id="genre">
  53. <input type="text" name="quantity" placeholder="Quantity" id="quantity">
  54. <input type="submit" name="submit" value="Submit"/>
  55. <!-- <button type="submit" name="submit"> Submit</button> -->
  56.  
  57. </form>
  58. </center>
  59.  
  60. <?php
  61. $title = $_POST['title'];
  62. $author = $_POST['author'];
  63. $genre = $_POST['genre'];
  64. $quantity = (int)$_POST['quantity'];
  65. $submit = $_POST['submit'];
  66.  
  67. if ($submit) {
  68. $sql = "INSERT INTO catalog (id, title, author, genre, quantity) VALUES (NULL, '$title', '$author', '$genre', '10');";
  69. mysqli_query($con, $sql);
  70. }
  71.  
  72. ?>
  73.  
  74. </body>
  75. </html>
Add Comment
Please, Sign In to add comment