【发布时间】:2017-09-19 02:38:57
【问题描述】:
我正在设计一个简单的图书应用程序。我有用户登录、出售或购买书籍,他们也有一些帐户设置,包括管理帖子,用户可以在其中删除他们添加到系统中的书籍。
我需要有关如何执行此操作的帮助。当用户按下“管理帖子”按钮时,我想要一个用户可以在其中键入 Book_ID 的输入字段和一个“删除”按钮,他们可以在其中单击它以将图书从系统中删除。
现在,当您添加一本书时,我无法将其设置为将其链接到登录的特定用户(不知道该怎么做),因此用户将能够删除任何书。我在这个项目上没时间了,所以我现在不用担心了。我只需要用户能够通过表上的字段查看数据库中的所有书籍:Book_ID、ISBN、Title、Author - 然后用户将 Book_ID 输入到输入字段中,单击“删除”按钮和book 被用户从数据库中删除。
数据库名称:nextbook 表:书籍 字段:book_ID、ISBN、作者、标题(希望查看这些)
以下是我从另一个页面获得的代码模板,我认为它会类似。除了,我需要将删除 SQL 放在某处:
<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
$query = "SELECT * FROM books";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM books";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "Admin", "Password", "nextbook");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<!--Html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" >
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="http://ie7-js.googlecode.com/svn/version2.1(beta4)/IE9.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style>
table {
border-collapse: collapse;
width: 30%;
}
th, td {
text-align: left;
padding: 5px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #007d5f;
color: white;
}
</style>
<link rel="stylesheet" href="NextBook1.css"/>
</head>
<body>
<div data-role="page" id="Manage_Posts">
<div data-role="header" data-theme="b">
<h1>NextBook</h1>
<a href="Login.php" data-icon="power" class="ui-btn-right" data-theme="a" data-mini="true">Sign Out</a>
</div>
<br>
<div class="logo" align="center">
<img src="Images/image1%20-%20Copy.PNG" width="100" height="100" ">
</div>
<div data-role="content" align="center">
<!--<form action="View_Search_Results_Table.php" method="post" align="center"> -->
<input type="text" name="deletepost" placeholder="Enter ISBN you want to delete">
<input type="submit" name="delete" value="Delete Post"><br><br>
<div style="overflow-x:auto;">
<table border="1px solid black;" align="center">
<tr>
<th>Book ID</th>
<th>ISBN</th>
<th>Title</th>
<th>Author</th>
</tr>
</div>
<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['Book_id'];?></td>
<td><?php echo $row['ISBN'];?></td>
<td><?php echo $row['Title'];?></td>
<td><?php echo $row['Author'];?></td>
</tr>
<?php endwhile;?>
</table>
<div data-role="footer" data-position="fixed" data-id="nav" data-theme="b">
<div data-role="navbar">
<ul>
<li><a href="Home_Page.php" data-icon="home" class="ui-btn-active ui-state-persist"></a></li>
<li><a href="#anylink" data-icon="alert"></a></li>
<li><a href="#anylink" data-icon="mail"></a></li>
<li><a href="Manage_User_Accounts.php" data-icon="gear"></a></li>
</ul>
</div>
</div>
</body>
</html>
【问题讨论】:
标签: php html sql phpmyadmin