1 00:00:00 --> 00:00:08 Welcome back! In our previous tutorial, we have established what we are going to change and how we are going to change it. 2 00:00:09 --> 00:00:10 We did go through that. 3 00:00:11 --> 00:00:12 So, now I will test my code. 4 00:00:13 --> 00:00:16 If we look at our database, we have a few records here. 5 00:00:17 --> 00:00:22 I am going to delete David's record here because it was from another tutorial. 6 00:00:23 --> 00:00:28 After the deletion, we have the records of Alex, Kyle, Emily and Dale 7 00:00:29 --> 00:00:33 Here I will use Kyle's record as an example and change it to a particular value. 8 00:00:34 --> 00:00:37 We will refresh our page and make sure it is updated. 9 00:00:38 --> 00:00:45 I will select "Kyle" and I will change this to "Karen" and I will click on "Change" and here everything has disappeared. 10 00:00:46 --> 00:00:49 Now we will come back into our table and click on "Browse" to refresh it. 11 00:00:50 --> 00:00:57 we will scroll down and find that nothing has changed. 12 00:00:58 --> 00:01:05 I think I made a mistake. My mistake was that it was "name" before and now I will change this to "value". 13 00:01:06 --> 00:01:08 This needs to be set to "value" instead of "name" 14 00:01:09 --> 00:01:14 "value" holds the value... of anything here that has been selected; so the value is "id". 15 00:01:15 --> 00:01:24 When we submit our form, it will come through and the value will be contained within here in "id". 16 00:01:25 --> 00:01:29 So, I found and fixed the problem and now I will go back and refresh. 17 00:01:30 --> 00:01:36 Here I will once again change "Kyle" to "Karen". By clicking on "Change" you can see that nothing has happened. 18 00:01:37 --> 00:01:41 Even when I enter my database, we can see that we have got Alex, Kyle, Emily and Dale. 19 00:01:42 --> 00:01:46 Since we had changed "Kyle" to "Karen", our id has shown visible changes. 20 00:01:47 --> 00:01:53 But when we click on "Browse" and scroll down, we can see that "Kyle" has now been replaced by "Karen". 21 00:01:54 --> 00:01:56 Hence, you can also update values using forms. 22 00:01:57 --> 00:02:14 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. 23 00:02:15 --> 00:02:19 You will be able to learn all this, as long as you learn the basic set of these tutorials. 24 00:02:20 --> 00:02:27 As if now, in this tutorial, you have learnt inserting and updating and so on so forth. 25 00:02:28 --> 00:02:33 The last thing I will show you is how to delete. 26 00:02:34 --> 00:02:45 To show you how to Delete, I will close this page and and remove this box and edit this. 27 00:02:46 --> 00:02:48 I will replace "Change" with "Delete". 28 00:02:49 --> 00:02:54 Here I will be deleting records where we have a particular name shown. 29 00:02:55 --> 00:03:00 To do this, I will add "lastname" over here. 30 00:03:01 --> 00:03:07 Let us now not resend that and let us go back to "mysql.php". 31 00:03:08 --> 00:03:16 Here we now have "Alex Garrett", "Karen Headen" which has been changed or modified from my last example. 32 00:03:17 --> 00:03:23 We will click "Karen Headen" and we will click on "Delete". This will delete the record. 33 00:03:24 --> 00:03:26 But it has not been deleted at the moment. 34 00:03:27 --> 00:03:30 Let us make sure all our records are intact first. 35 00:03:31 --> 00:03:36 As you can see here, we have all our records intact and I will choose to delete a particular record. 36 00:03:37 --> 00:03:44 Let us say delete "Emily Headen", so I will choose the record of Emily Headen to be deleted. 37 00:03:45 --> 00:03:51 Now we need to submit this to a new page called "mysql underscore delete.php". 38 00:03:52 --> 00:03:58 For this, we are going to create a new page save as mysql underscore delete.php 39 00:03:59 --> 00:04:02 We will do exactly the same as we had done before. 40 00:04:03 --> 00:04:09 We are going to "require" our connect so we need to connect to the database. 41 00:04:10 --> 00:04:21 Oh Sorry! Let us get that back to "require connect.php" and we will again take the variables in. 42 00:04:22 --> 00:04:28 So let us type "todelete" here and that is "equal to" again a "POST" variable here. 43 00:04:29 --> 00:04:33 We are posting this form to this page and let us change some values over here. 44 00:04:34 --> 00:04:36 Let us say "todelete". 45 00:04:37 --> 00:04:40 So we have changed our "select name" to "todelete". 46 00:04:41 --> 00:04:46 Now, if you have a look back on this form here, I will show you the code again. 47 00:04:47 --> 00:04:53 Here we can see that we have our name values and our id value here for each case of each record. 48 00:04:54 --> 00:05:00 If we refresh, the name of our form is "todelete" and we are taking that into account for each value. 49 00:05:01 --> 00:05:07 If Emily's record has been selected we will delete the record where the id is equal to 3. 50 00:05:08 --> 00:05:13 Let us go back to our code and here we have our POST variable. 51 00:05:14 --> 00:05:19 Now I am going to echo out to give you an example of how it is processed. 52 00:05:20 --> 00:05:29 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. 53 00:05:30 --> 00:05:40 Here, again we will create a new variable and I will call it "mysql underscore query". 54 00:05:41 --> 00:05:44 Inside here we will use a whole new set of commands. 55 00:05:45 --> 00:05:51 We will type in "DELETE FROM" and obviously we will specify our table. 56 00:05:52 --> 00:05:56 Let us type "people" and "WHERE id equals "todelete". 57 00:05:57 --> 00:06:02 The "todelete" variable which is the id of the person that we selected from this list. 58 00:06:03 --> 00:06:07 Now let us test this. Let us say Emily Headen. 59 00:06:08 --> 00:06:12 Let us check in our database if Emily Headen's record still exists. 60 00:06:13 --> 00:06:16 Let us refresh to see if the record still exists. 61 00:06:17 --> 00:06:21 When I click on "Emily Headen" and click on "Delete", nothing has happened. 62 00:06:22 --> 00:06:29 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. 63 00:06:30 --> 00:06:42 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. 64 00:06:43 --> 00:06:49 If I have forgotten anything, please let me know and I will add it as parts of these tutorials. 65 00:06:50 --> 00:06:52 Make sure you subscribe for updates from my channel. 66 00:06:53 --> 00:06:54 I hope you enjoyed these tutorials. Thanks for watching. 67 00:06:55 --> 00:07:00 This is Evan Varkey dubbing for the Spoken Tutorial Project. (Script contributed by Juanita Jayakar).