Welcome back.
Now it's time to work on editing project images.
So each project, as you have seen, has four images.
And we need for it for for this we need to edit four images.
If you want to edit the images, we need to allow the army to edit the images and editing product images
is not going to be included in the same edit.
This edit will allow you to edit text information such as the the title description, the price by the
category, the color and the special offer.
However, if you want to edit the images, I'm going to create another page for this because images
are different and they require a different logic.
Therefore, it's better to add them in a new page.
So I have created a file called Edit Images and I created a form here again.
And this form has the following.
It has first, this form has ink type multipart four slash form data.
Again, this is important because I'm uploading images and then the method is passed, the image is
passed and the action is going to be update underscore images that BHP, which is a file that I'm going
to walk you through shortly and then inside that form I have two hidden inputs.
The first input is the product ID, the second input is the product name.
Why do we need these?
We need these because I'm going to be using the product ID to get the two to to update the the, the
images, the name of the images in the database.
And we need the product name to give names to the images that we will be uploading shortly.
And then I have you for inputs.
Each input is a file and each input has an m and the name is Image one, two, three, four respectively.
That's it.
Let me show you this.
So if I go to if I go to edit underscore images, actually, I will not be able to go to this page because
I protected this page at the top.
I said, Here, let me show you the logic.
So at the top I said, If if we don't have the product ID, then we cannot go to the beach.
We need to pass a product ID, so let's do this to do this.
Remember, in the products in the product table, we need to add here a column that has buttons that
will allow the admin to edit each.
To allow images of each single product.
So to do this, we need to look for the column.
So here we have edit.
And we can add the added images so we can create a new column here.
And that column now is going to be apparent.
That's going to allow you to edit, edit images.
And in order to enter the images, we need to add the link.
So the link is going to be similar to edit.
I'm going to copy this and paste it above the edit.
I'm going to pasted above the edit.
However, the trick is going to be different, so the trick is going to be edit.
Edit.
Underscore images.
Got BHP and then we need to pass the project.
Eddie, brother Eddie is equal to brother Eddie.
And we need to say here and.
And.
Product.
Underscore name.
Is equal to and then another BHP.
And in order not to confuse you, let me let me write let me type this in a new format, in a different
format, because this is getting complicated.
So to retype this, let me copy this part.
ALIMI Remove it, and then I'm going to say your echo.
And what I'm going to echo is that I'm going to echo the the file name, which is edit images that reach
me and then question mark.
Product underscore ID is equal to and then double cross and then dot and then I append the product ID
to it.
And then at the end I say, I say dot and then I'm going to spend a new parameter.
I'm going to say and.
Project underscore name is equal to and then is equal to what is equal to dot and then project.
Product and then product.
Underscore that, underscore name.
Very, very simple and straightforward.
Again, that's the the iterative is BHP Echo and then it it emerges that BHP was your market product.
It is equal to product ID and product name is equal to product product name.
And then the button is going to say, edit images.
Edit images.
Laney.
I'll show you this.
So now if I refresh, this is going to display here edit images.
So you can edit the images and you can even give it a different color.
You can see here, meet the end primary danger.
You can say anything else.
You can see, for example.
Or Nick.
I think this is going to be.
A kind of yellow color.
Yes, this is a yellow color.
So when you click on edit, if I click on edit, it's going to take me.
Let me click on it.
As you can see, it's going to take me to this page, which is the edit images that are up and running
it is equal to one.
And product name is equal to shoes to the yellow shoots.
And if you go back and click on edit of the second you should you have product ID is equal to two and
product name is equal to green back.
So this is the form.
Well, now in the form, let me go back to the form now only the form.
The logic is the following.
The logic is that if a user clicks on this button, which is which has a name called update images,
this file will be executed.
What?
What's this file?
This files called update underscore images that BHP.
So I have created this file.
This file is called update images that BHP.
And what this file does is that this file uploads the images, it just uploaded images, nothing more.
And of course it updates the names of the images in the database.
So let me walk you through the logic.
We have already done this, but this is slightly different.
So first I included the connection as usual.
And then here I need to make sure that user clicked on the update images button and then I got the product
name and the product ID from the form.
Remember I have here product ID and product name in the form in this form.
And then I got the images.
Image one, image two, image three, image four because they have these names, they have image one,
two, three, four names.
These are the names.
And then we need to say temp name to get the file, to get the to get the images.
And then we need to give these images names again, the name.
In order for the name to be unique, we need to we need to give it any name of the name of the product.
So the product name is product name.
And then I appended one JPEG to the first image and then to that JP to the second, and then three the
JPEG to the third and then for the JPEG to the fourth.
Finally I just uploaded the, the images using the move uploaded file.
Bypassing firstly the file itself, which is image one.
And then the second parameter is that that assets for slash images for slash the image name.
Again, the reason why I'm saying that that is because now I'm inside the admin and in order in order
to go back, in order to get out of the admin, we need to say that, that and then we need to enter,
enter the assets folder and then we need to enter the images folder and then we need to store the image
in the images folder with this name with name one name with image, name one image, name two image,
name three and image name four.
So this is the part one.
Part one is uploading the images.
Part two is updating the names in the database.
So to obtain the names in the database, we just say update products, set product image is equal to
is equal to question mark and then comma product image two is equal to question mark.
And then product image three is equal to the question mark.
And then product image four is equal to our question mark.
And again, the, the, the columns are the columns are product image and then product image to product
image pre and product image four.
That's why I'm saying a product image and then product image to product imagery product image for of
course with the with underscores in between.
Lastly, I said.
Is the empty bind ss i because they upload because they pass year the image.
Uh, which is wrong again.
This is wrong.
We need to pass the image.
Our name again.
I have done this intentionally to show you that this is a mistake that many developers do.
You need to save your image.
Me image.
Because here.
Here.
I'm not.
Here, I'm not.
Here.
I'm not.
I'm not uploading damage here.
I'm updating the name of the image.
Therefore, we need to pass the names.
Not the files, not the images, the names of the images.
So here we need to say image.
Name one.
Image.
Name two, image.
Name three and image.
Name four.
And then we say product ID, which is the product ID.
Which is this practically because because given the product, it will we will be updating that that
specific product images.
And then finally, I said to your excuse and if if the execution was successful, I go to the product
page with a message and that message has a key called images underscore updated.
And the message yourself is images have been updated successfully.
Else I go to the products that B2B and I have a key called images underscore failed and it says error
occurred.
Try again.
And then in the products I displayed the errors using the using.
Here, let me show you where it is.
It's here.
So here I use the these key images underscore updated and the images underscore updated and the image
has failed.
If if you set the image, if you say forget images failed I display I echo the get images failed where
there is color here and with a green color in case of success.
And finally, I'm going to click on file and then stable.
Now us.
So now let me go back.
Let me, for example, if it's one of these files, I'm going to go to the last image.
I'm going to go to the last product.
This is the last part.
So I'm going to change the image of this product.
I'm going to click on edit images and then I'm going to select another image.
Lamy Select.
For example, aim is to look at this image for the first image.
So I'm just going to change the order to show you that it will work successfully.
Now if I click on Update in case of success, it's going to say here images have been updated, updated
successfully.
How would you know?
How would you verify that images have been updated successfully?
Well, you can go to the last page and check that.
You can go to the product, which is this product, as you can see, there it is now the image is different,
which is correct.
So the image has been updated, successful images have been updated successfully, and you can check
that in the database, even in the database.
But the since the names are the same, the names will not be different because the name of the product
is the same, the name of the product is the same.
And you can check, of course, that in the.
In the.
In your project.
You should find the first image here.
Read.
Read, write, choose one.
Is this image now?
It's this image because here it says we choose this image.
So it works successfully.
And now we know how to edit images.
That's.