Advertisement
conception

Php 4

Feb 16th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Add to Bookstore</title>
  7. <link rel="stylesheet" type="text/css" href="style.css" />
  8. </head>
  9. <body>
  10. <div id="navi"><center><a href="index.html" class="navlink"> Bookstore Home</a> ||
  11. <a href="bookstore.html" class="navlink">Add Book to Store</a> ||
  12. <a href="report.php" class="navlink">List Books</a> ||
  13. <a href="deletebook.html" class="navlink">Delete Book from Store</a></div><center>
  14. <div class="overlay">
  15. <div class="innerbox" id="box">
  16. <h2>Add to Bookstore</h2>
  17.  
  18. <?php
  19. // php variable assignments to names used in HTML file
  20. $title = $_POST['title'];
  21. $last_name = $_POST['alastname'];
  22. $first_name = $_POST['afirstname'];
  23. $format = $_POST['format'];
  24. $price = $_POST['price'];
  25. $isbn = $_POST['isbn'];
  26.  
  27. // check inputs
  28. if ( empty($title) ) {
  29. echo "You must enter a book title. <br />";
  30. }
  31.  
  32. if (strlen($isbn)!=10) {
  33. echo "ISBN-10 must be 10 Characters/Numbers long. <br />";
  34. // ISBN codes also include letters occasionally so this should not be made numeric.
  35. }
  36.  
  37.  
  38. //run only if title is includes and ISBN is 10 numbers/letters long
  39. if ( !empty($title) && strlen($isbn==10) ) {
  40. // connect to database using login info, and database name
  41. $dbc = mysqli_connect('localhost', 'root', '', 'bookstore_kariann')
  42. or die('Error connecting to MySQL server.'); // terminates code if failed
  43.  
  44.  
  45. // creates the SQL query and stores as string in a PHP variable
  46. $query = "INSERT INTO books (title, author_last, author_first, format, price, isbncode) " .
  47. "VALUES ('$title', '$last_name', '$first_name', '$format', '$price', '$isbn')";
  48.  
  49.  
  50. /* testing echoes
  51. echo $query;
  52. echo '<br />'; */
  53.  
  54.  
  55. // isses the query using the msqli_query function that allows it to add data to the database table
  56. $result = mysqli_query($dbc, $query)
  57. or die('Error querying database.'); // terminates if failed
  58.  
  59. mysqli_close($dbc); // close connection
  60.  
  61. // output for data submitted
  62. echo '<h3>Book has been entered into database.</h3><br />';
  63. echo 'Title: ' . $title . '<br />';
  64. echo 'Author Last Name: ' . $last_name . '<br />';
  65. echo 'Author First Name: ' . $first_name . '<br />';
  66. echo 'Format: ' . $format . '<br />';
  67. echo 'Price: ' . $price . '<br />';
  68. echo 'ISBN-10: ' . $isbn . '<br />'; }
  69. ?>
  70. </div></div></center>
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement