Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MNConnor authored Nov 23, 2021
1 parent d38ce5c commit f616136
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 26 deletions.
146 changes: 123 additions & 23 deletions Books.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,21 @@
<h2 style="text-align:center">Find Book</h2>
<form action="" method="POST" style="align-content: center">
<p style="font-size:200%;">
<input type="text" id="booksearch" name="booksearch" placeholder="Book"/><br>
<input type="text" id="booksearch" name="booksearch" placeholder="Enter Book Title or Author Name"/><br>
<input type="submit" name="bookSearchButton" style="background-color:green;color:white" value="Search"/>
</p>
</form>
<?php
if(isset($_POST['bookSearchButton']))
{
getBooksTable();
}
if(array_key_exists('editBook_ID',$_POST))
{
editBookInfo($_POST['editBook_ID']);
}
?>



</div>
Expand All @@ -54,19 +65,19 @@
</html>

<?php
$FindBookResults = null;

function setBookResults($result)
{
global $FindBookResults;
$FindBookResults = $result;
}
//$FindBookResults = null;
//
//function setBookResults($result)
//{
// global $FindBookResults;
// $FindBookResults = $result;
//}

function getBookResults()
{
global $FindBookResults;
return $FindBookResults;
}
//function getBookResults()
//{
// global $FindBookResults;
// return $FindBookResults;
//}

function makeDBconnection()
{
Expand Down Expand Up @@ -108,16 +119,16 @@ function test_input($data)
return $data;
}

if(isset($_POST['bookSearchButton']))
function getBooksTable()
{ //check if form was submitted
$conn = makeDBconnection();
$input = $_POST['booksearch']; //get input text
$input = test_input($input); // Clean input data
$sql = "SELECT * FROM BOOKSTORE.BOOKS WHERE Title LIKE \"%{$input}%\"";
$sql = "SELECT BOOKS.BookID, Books.Title, Author.First_Name, Author.Last_Name FROM BOOKSTORE.BOOKS JOIN BOOKSTORE.AUTHOR ON BOOKS.AuthID = Author.AuthID WHERE Books.Title LIKE \"%{$input}%\" OR Author.First_Name LIKE \"%{$input}%\" OR Author.Last_Name LIKE \"%{$input}%\"";
mysqli_query($conn, $sql);
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
global $FindBookResults;
$FindBookResults = $result;
// global $FindBookResults;
// $FindBookResults = $result;
?>

<table>
Expand All @@ -126,21 +137,27 @@ function test_input($data)
<td colspan="3" style="text-align:center">Books</td>
</tr>
<tr>
<td>BookID</td>
<td>Edit</td>
<td>Title</td>
<td>AuthID</td>
<td>Author</td>
</tr>
</thead>
<tbody>
<?php
$result = getBookResults();
// $result = getBookResults();
while ($row = mysqli_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $row['BookID']?></td>
<td>
<!-- EDIT BUTTON-->
<form method="post">
<input type="submit" name="editBook" id="editBook" value="Edit"/>
<input type="hidden" name="editBook_ID" value="<?php echo $row['BookID']; ?>"/>
</form>
</td>
<td><?php echo $row['Title']?></td>
<td><?php echo $row['AuthID']?></td>
<td><?php echo $row['First_Name'] . " " . $row['Last_Name']?></td>
</tr>

<?php
Expand All @@ -154,5 +171,88 @@ function test_input($data)
</table>
<?php
}
?>

function editBookInfo($BookID)
{
$conn = makeDBconnection();
$sql = "SELECT * FROM BOOKSTORE.BOOKS JOIN BOOKSTORE.AUTHOR ON BOOKS.AuthID = Author.AuthID JOIN BOOKSTORE.EDITION ON Books.BookID = edition.BookID WHERE Books.BookID = \"{$BookID}\";";
mysqli_query($conn, $sql);
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$row = mysqli_fetch_assoc($result);
?>
<form method="POST" action="" id="my_form"></form>
<table>
<td colspan="3" style="text-align:center">Book Details</td>
</tr>
<tr>
<td>Book ID</td>
<td>Title</td>
<td>Author</td>
</tr>
<tr>
<td>
<input type="text" name="BookIDValue" form="my_form" value="<?php echo $row['BookID'];?>" />
</td>
<td>
<input type="text" name="TitleValue" form="my_form" value="<?php echo $row['Title'];?>" />
</td>
<td>
<select name="AuthIDValue" id="AuthIDValue" form="my_form">
<option selected name="AuthIDValue" value=<?php echo $row['AuthID'];?>> <?php echo $row['First_Name'] . " " . $row['Last_Name'];?> </option>
<?php
mysqli_free_result($result);
$sql = "SELECT AuthID, First_Name, Last_Name FROM BOOKSTORE.AUTHOR";
mysqli_query($conn, $sql);
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result))
{
?>
<option name="AuthIDValue" value=<?php echo $row['AuthID'];?>> <?php echo $row['First_Name'] . " " . $row['Last_Name'];?> </option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="3" style="text-align:center">Pricing</td>
</tr>
<?php
$sql = "SELECT * FROM BOOKSTORE.BOOKS JOIN BOOKSTORE.AUTHOR ON BOOKS.AuthID = Author.AuthID JOIN BOOKSTORE.EDITION ON Books.BookID = edition.BookID WHERE Books.BookID = \"{$BookID}\";";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result))
{
?>
<tr>
<td colspan="2"><?php echo $row['Format'];?></td>
<td>
<input type="text" name="<?php echo explode(" ", $row['Format'])[0];?>" form="my_form" value="<?php echo $row['Price'];?>" />
</td>
</tr>
<?php
}

?>
</table>
<input type="submit" name="editBooksSubmitButton" form="my_form" value="Submit"/>
<div id='map' style='width: 400px; height: 300px;'></div>
<?php
}

if(isset($_POST['editBooksSubmitButton']))
{
echo("<p>{$_POST['TitleValue']} has been updated</p>");
$conn = makeDBconnection();
$sql = "UPDATE BOOKSTORE.BOOKS SET BookID=\"{$_POST['BookIDValue']}\", Title=\"{$_POST['TitleValue']}\", AuthID=\"{$_POST['AuthIDValue']}\" WHERE Books.BookID = \"{$_POST['BookIDValue']}\"";
mysqli_query($conn, $sql);

$sql = "SELECT * FROM BOOKSTORE.BOOKS JOIN BOOKSTORE.AUTHOR ON BOOKS.AuthID = Author.AuthID JOIN BOOKSTORE.EDITION ON Books.BookID = edition.BookID WHERE Books.BookID = \"{$_POST['BookIDValue']}\";";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result))
{
$sql = "UPDATE BOOKSTORE.EDITION SET PRICE = \"{$_POST[explode(" ", $row['Format'])[0]]}\" WHERE BOOKID = \"{$_POST['BookIDValue']}\" AND FORMAT = \"{$row['Format']}\"";
mysqli_query($conn, $sql);
}
}
?>

1 change: 1 addition & 0 deletions DB_USER.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root Winona2021!
6 changes: 3 additions & 3 deletions Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<p style="font-size:200%;">
<input type="text" id="usernamebox" name="user" placeholder="Username"/><br>
<input type="password" id="passwordbox" name="pass" placeholder="Password"/><br>
<input type="submit" style="background-color:green;color:white" value="Submit"/>
<input type="submit" value="Submit"/>
</p>
</form>
<hr><br>
Expand Down Expand Up @@ -57,8 +57,8 @@ function getRandomUser()
<script type="text/javascript">
var usernamebox = document.getElementById("usernamebox");
var passwordbox = document.getElementById("passwordbox");
usernamebox.value = "<?php echo $row['username'];?>";
passwordbox.value = "<?php echo $row['password'];?>";
usernamebox.value = "<?php echo $row['UserID'];?>";
passwordbox.value = "<?php echo $row['Password'];?>";
</script>
<?php

Expand Down

0 comments on commit f616136

Please sign in to comment.