Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Add to Bookstore</title>
- <link rel="stylesheet" type="text/css" href="style.css" />
- </head>
- <body>
- <div id="navi"><center><a href="index.html" class="navlink"> Bookstore Home</a> ||
- <a href="bookstore.html" class="navlink">Add Book to Store</a> ||
- <a href="report.php" class="navlink">List Books</a> ||
- <a href="deletebook.html" class="navlink">Delete Book from Store</a></div><center>
- <div class="overlay">
- <div class="innerbox" id="box">
- <h2>Add to Bookstore</h2>
- <?php
- // php variable assignments to names used in HTML file
- $title = $_POST['title'];
- $last_name = $_POST['alastname'];
- $first_name = $_POST['afirstname'];
- $format = $_POST['format'];
- $price = $_POST['price'];
- $isbn = $_POST['isbn'];
- // check inputs
- if ( empty($title) ) {
- echo "You must enter a book title. <br />";
- }
- if (strlen($isbn)!=10) {
- echo "ISBN-10 must be 10 Characters/Numbers long. <br />";
- // ISBN codes also include letters occasionally so this should not be made numeric.
- }
- //run only if title is includes and ISBN is 10 numbers/letters long
- if ( !empty($title) && strlen($isbn==10) ) {
- // connect to database using login info, and database name
- $dbc = mysqli_connect('localhost', 'root', '', 'bookstore_kariann')
- or die('Error connecting to MySQL server.'); // terminates code if failed
- // creates the SQL query and stores as string in a PHP variable
- $query = "INSERT INTO books (title, author_last, author_first, format, price, isbncode) " .
- "VALUES ('$title', '$last_name', '$first_name', '$format', '$price', '$isbn')";
- /* testing echoes
- echo $query;
- echo '<br />'; */
- // isses the query using the msqli_query function that allows it to add data to the database table
- $result = mysqli_query($dbc, $query)
- or die('Error querying database.'); // terminates if failed
- mysqli_close($dbc); // close connection
- // output for data submitted
- echo '<h3>Book has been entered into database.</h3><br />';
- echo 'Title: ' . $title . '<br />';
- echo 'Author Last Name: ' . $last_name . '<br />';
- echo 'Author First Name: ' . $first_name . '<br />';
- echo 'Format: ' . $format . '<br />';
- echo 'Price: ' . $price . '<br />';
- echo 'ISBN-10: ' . $isbn . '<br />'; }
- ?>
- </div></div></center>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement