What I mean is all my data are currently stored in phpMyAdmin and what I’m trying to accomplish is to search the value store by ID. Now, it is possible but after watching your PHP Code Along video , I want to include a button where I can delete the items straight away. The way how I add the database is just by searching it using ID so I just one to create a workable delete button. However, I’m not sure if it is possible to create a button directly through phpMyAdmin because if it is a text, then I have no problem but if it is a button, I’m not so sure about it
<html>
<head>
<link rel="stylesheet" href="css/booklist.css">
<title>Search data by its ID</title>
<script type="text/javascript">
function out(){
alert("Checkout Items Successful!");
}
</script>
</head>
<div class ="background">
<h1>Library Checkout System</h1>
<h2>Loan/Request Your Books Here</h2>
<form action="" method="POST">
<input type="text" name="id" placeholder="Please enter Book ID" />
<input type="submit" name="search" value="Search By ID" />
</form>
<table border="2" id="newton">
<tr>
<th>Product Name</th>
<th>Quantity</th>
<th>Returned Date</th>
</tr><br><br>
<?php
$connection = mysqli_connect("localhost","root", "");
$db = mysqli_select_db($connection,"myfirstdb");
session_start();
if (!isset($_SESSION['id'])) {
$_SESSION['id'] = array();
}
if(isset($_POST['search']))
{
$id = $_POST['id'];
array_push($_SESSION['id'],$id); //Here we have declared a session array. We can add elements to it by array_push function.//
$_SESSION['id'] = array_unique($_SESSION['id']); //array_unique: Removes duplicate values from an array
$id = implode(',',$_SESSION['id']); //implode : returns a strings from the elements of an array.//
// instead of changing the database of each row, the implode() function adds the rows according to the selected id entered.//
// this function is the key for solving my original problem.//
$query = "SELECT * FROM `table3` where id in ($id)";
$query_run = mysqli_query($connection, $query);
while($row = mysqli_fetch_array($query_run))
{
?>
<tr>
<td>
<?php echo $row ['product_name']; ?> </td>
<td>
<?php echo $row ['quantity']; ?> </td>
<td>
<?php echo $row ['returned_date']; ?> </td>
</tr>
<?php
}
}
?>
</table>
<br>
<input type="submit" name="send" value="Confirm Booklist" onclick="out()" />
</form>
</div>
</body>
</html>
I’m not sure I understand. Do you need a button to remove an item from the book list?
or do you want to delete the book from the database for good?
If yes why would you do that in a checkout system?
not true: phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL over the Web (source)
your data is stored in a mysql database.
you can just make the button (which really should be form with submit button) in html, and then inject the id of your product.
Yes, you are right about that. Can you actually create a button through phpMyAdmin?
Not through phpMyAdmin, but you can code it
you can just make the button (which really should be form with submit button) in html, and then inject the id of your product.
phpMyAdmin is a tool to manage your database through a web interface. This interface should already contain the functionality to delete rows.
your are trying to build your own website, from which rows can be deleted through php.
its important to understand each piece (php, mysql, PhpMyAdmin) of the puzzle
given PhpMyAdmin is a web interface to manage your database, PhpMyAdmin not having delete functionality would be very stupid.
Just now, you mentioned why would I do that in a checkout system. Well, that is just my idea, but in your opinion do u think my page would be better off would a delete button or everything is fine with my page at the moment?
I’m very confused by this discussion. phpMyAdmin obviously allows to delete items in a table, but I don’t think this is what our friend wants to do?
@web7481176285
I think you should add a button that allows users to remove a book from the list, but not delete the book entirely from the database.
I think you should be able to delete rows from your database
libraries get new books and old books are sold or discarded. If a library had the same books for all eternity would not be good for business.
he wants to build his own functionality to delete books. Which I would encourage him to do.
but then you refresh the page, and the book which you removed is magically back. Or how did you envision this @ghostlovescore?
It really depends if this is an admin panel or not for his library?
This looks to me like a checkout page that allows a student to borrow books from his uni library (which they’ll have to return eventually, so no deleting the books). I may be wrong, though.
But I’m still confused as to what @web7481176285 really wants to do here.
I thought about creating a delete button to delete the database that I entered earlier. However, that is just my idea. That’s why, in your opinion, I would like to know whether it makes sense to have a delete button at the side of each database? If so, any tips or what functions should I use to create the delete button for each row of ID I entered?
Let’s try what it is you want to do, and then you’ll see for yourself if the result is satisfying or not.
So, what you can do is add an extra <td></td>
after your $row['returned_date']
column.
Inside, create a form with a button (with a name of “delete_item”, for example), as well as an input of type hidden. The value of this hidden field should be the id of the book. Simply echo $row['id']
.
Then it’s quite simple. Just check that the button “delete_item” has been triggered, and make a query to delete from table3 where id = the id to delete.
You’ll find that you’ll run into trouble with all this, especially considering the way you’re using $_SESSION (shouldn’t really be used that way, but I understand what you’re trying to do with it…).
Also, you really should be separating concerns. A database connection should not be placed inside of a HTML table, nor inside a HTML page for that matter.
The database connection should be in a single PHP file.
The queries should be in another PHP file.
And then the HTML should only display the result of the queries.
You’ll find that everything becomes much clearer, and simpler, once you do this 
But for now, try to make the delete button happen and let us know how it goes!
Please ask if you need more help.