Welcome back.
Now it's time to work on deleting a product.
How would you delete a product if you want to do so?
Well, it's very simple.
Let's start working on it.
So the first thing I'm going to do is that I'm going to create a file that's going to be responsible
for deleting a product.
I'm going to say your new.
You file?
You file.
Then I'm going to say delete underscore products, not BHP.
And then what I'm going to do in this file, the first thing I'm going to do is that I'm going to get
a card from here.
First, I'm going to copy this code.
I'm going to make sure that the user, the admin, is logged in.
And the next thing that I'm going to do is that I'm going to activate the button.
So I'm going to go to the products.
And in the products.
What I want to do is that, remember, we have this button, we have edit and delete.
Let's work on the delete.
On the delete.
What we want to do is that we want to say a trip is equal to delete.
Rather got BHP and then I'm going to say product underscore ID is equal to.
BHP and then Echo.
Product.
I'd.
And that's it.
Year we have a product I.D. and we can delete that product and the product now in the product, in the
delete product, what we want to do is that we want to say it's.
Is it?
Product 80 get first get product ID.
Project I.D. then.
Then if we have the product ready.
What I'm going to do is that I'm going to delete that product and to delete a product from the database,
we need to get a command.
Let me get a command instead of writing it from scratch.
So here so I'm going to get this command, let me get these lines and then maybe paste them here.
And then I'm going to change up.
I'm going to change a few things.
First, I'm going to say statement is equal to connect, repair and then delete the lead.
From.
From where?
From.
We need to delete from products.
Products where.
Where product I.D. is equal to question mark.
And then we say statement bind, bind by RAM.
And then we bind the I, the product ID, product ID.
And we just excused one and that's it.
We need to remove all of these and we need to get the product ID and do a few things.
The first thing that we need to do is, is that at the top we need to import the session.
I'm going to say session start.
Session start.
The next thing that we need to do is that we need to import the the server connection server.
Connection.
And then we need to get a product I.D. So to get the product I.D., we need to store it in a new variable
here.
I'm going to say product underscore I.D. is equal to get.
Get.
Productivity, product R&D.
And lastly, if everything's fine, we just redirect.
We say here, hey there, and then location.
And then.
Products that BHP and then I'm going to say delete.
Deleted.
Set says for.
Successfully.
And then I'm going to say is equal to product has been deleted successfully.
And you can add if statement to check whether the product has been deleted or not.
You can say here if and then if product has been deleted successfully, you can take the user to this
page and else else you can display the same message, the same the same line.
You can use the same line, but with with a different message.
You can say delete, deleted.
Failure.
Message fail.
Failure.
Just failure.
And then here couldn't defeat the product.
Good night.
The elite product.
And then in the in the in the product speech, we need to display these messages.
So here, remember, we have we have this code, we can copy this code and then we can paste it here
in case of failure, we, we say delete, delete.
The key was I think delete it failure.
Related failure.
And we just say delete it.
Failure.
Delete it.
Failure.
And in case of success, we copy the same message.
And this place here.
And then we see it.
It's this message, and instead of it, it's a message.
The message was deleted, successful, deleted, successful.
So I'm going to copy it.
And then I'm going to sit here.
Deleted.
Successfully and he deleted successfully.
That's it.
Pretty simple and awesome.
Let me now heading over to the browser at this.
Let me let me refresh first and then we have here we should have here all of the products.
Let me delete the last product because I don't want the last product from my system.
So the last product is this one, the green shoots.
Click on delete.
And if you click on delete it, as you can see, it says product has been deleted successfully.
Let's verify this leaning.
Go to the last page.
So as you can see, if I go to the last page, the product has been deleted successfully.