Welcome back! In our previous tutorial, we have established what we are going to change and how we are going to change it.
We did go through that.
So, now I will test my code.
If we look at our database, we have a few records here.
I am going to delete David's record here because it was from another tutorial.
After the deletion, we have the records of Alex, Kyle, Emily and Dale
Here I will use Kyle's record as an example and change it to a particular value.
We will refresh our page and make sure it is updated.
I will select "Kyle" and I will change this to "Karen" and I will click on "Change" and here everything has disappeared.
Now we will come back into our table and click on "Browse" to refresh it.
we will scroll down and find that nothing has changed.
I think I made a mistake. My mistake was that it was "name" before and now I will change this to "value".
This needs to be set to "value" instead of "name"
"value" holds the value... of anything here that has been selected; so the value is "id".
When we submit our form, it will come through and the value will be contained within here in "id".
So, I found and fixed the problem and now I will go back and refresh.
Here I will once again change "Kyle" to "Karen". By clicking on "Change" you can see that nothing has happened.
Even when I enter my database, we can see that we have got Alex, Kyle, Emily and Dale.
Since we had changed "Kyle" to "Karen", our id has shown visible changes.
But when we click on "Browse" and scroll down, we can see that "Kyle" has now been replaced by "Karen".
Hence, you can also update values using forms.
It is very easy, as long as you have a standard knowledge of php software, how to manipulate things, how to check things, how to use if statements, passing variables, particularly the posting variables etc.
You will be able to learn all this, as long as you learn the basic set of these tutorials.
As if now, in this tutorial, you have learnt inserting and updating and so on so forth.
The last thing I will show you is how to delete.
To show you how to Delete, I will close this page and and remove this box and edit this.
I will replace "Change" with "Delete".
Here I will be deleting records where we have a particular name shown.
To do this, I will add "lastname" over here.
Let us now not resend that and let us go back to "mysql.php".
Here we now have "Alex Garrett", "Karen Headen" which has been changed or modified from my last example.
We will click "Karen Headen" and we will click on "Delete". This will delete the record.
But it has not been deleted at the moment.
Let us make sure all our records are intact first.
As you can see here, we have all our records intact and I will choose to delete a particular record.
Let us say delete "Emily Headen", so I will choose the record of Emily Headen to be deleted.
Now we need to submit this to a new page called "mysql underscore delete.php".
For this, we are going to create a new page save as mysql underscore delete.php
We will do exactly the same as we had done before.
We are going to "require" our connect so we need to connect to the database.
Oh Sorry! Let us get that back to "require connect.php" and we will again take the variables in.
So let us type "todelete" here and that is "equal to" again a "POST" variable here.
We are posting this form to this page and let us change some values over here.
Let us say "todelete".
So we have changed our "select name" to "todelete".
Now, if you have a look back on this form here, I will show you the code again.
Here we can see that we have our name values and our id value here for each case of each record.
If we refresh, the name of our form is "todelete" and we are taking that into account for each value.
If Emily's record has been selected we will delete the record where the id is equal to 3.
Let us go back to our code and here we have our POST variable.
Now I am going to echo out to give you an example of how it is processed.
We have Emily Headen here. We have 3 there which means that we can use this to delete the id 3 in the database or rather the table.
Here, again we will create a new variable and I will call it "mysql underscore query".
Inside here we will use a whole new set of commands.
We will type in "DELETE FROM" and obviously we will specify our table.
Let us type "people" and "WHERE id equals "todelete".
The "todelete" variable which is the id of the person that we selected from this list.
Now let us test this. Let us say Emily Headen.
Let us check in our database if Emily Headen's record still exists.
Let us refresh to see if the record still exists.
When I click on "Emily Headen" and click on "Delete", nothing has happened.
We have not echoed out but when we click on "Browse" to refresh, we can see that Emily's record has been deleted from the database.
So in this set of tutorials, I have shown you a basic serve command like how to insert data how to read data how to modify how to delete data and how to incorporate into html forms.
If I have forgotten anything, please let me know and I will add it as parts of these tutorials.
Make sure you subscribe for updates from my channel.
I hope you enjoyed these tutorials. Thanks for watching.
This is Evan Varkey dubbing for the Spoken Tutorial Project. (Script contributed by Juanita Jayakar).