Difference between revisions of "PHP-and-MySQL/C3/MySQL-Part-7/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 27: Line 27:
 
|We are also going to change our '''form''' here, so we don't need this for now.
 
|We are also going to change our '''form''' here, so we don't need this for now.
 
|-
 
|-
|00 :47
+
|00:47
 
|Let us delete that.
 
|Let us delete that.
 
|-
 
|-
Line 76: Line 76:
 
|-
 
|-
 
|02:28
 
|02:28
|Let us get rid of this dialogue box.
+
|Let us get rid of this dialog box.
 
|-
 
|-
 
|02:31
 
|02:31
Line 100: Line 100:
 
|-
 
|-
 
|03:24
 
|03:24
|The reason for not incorporating this inside our '''while''' loop is because if it is repeating then it is going to repeat the start and the end tags and not the '''option''' part which we need.
+
|The reason for not incorporating this inside our '''while''' loop is because if it is repeating then it is going to repeat the start and the end '''tags''' and not the '''option''' part which we need.
 
|-
 
|-
 
|03:36
 
|03:36
Line 106: Line 106:
 
|-
 
|-
 
|03:39
 
|03:39
|Let me echo out, let's say the "firstname".  
+
|Let me echo out, let's say the "$firstname".  
 
|-
 
|-
 
|03:42
 
|03:42
|And what this does is, for every record, it is going to echo this option code.
+
|And what this does is, for every record, it is going to echo out this option code.
 
|-
 
|-
 
|03:48
 
|03:48
|And if you remember down here, we had "option" and "option end".  
+
|And if you remember down here, we had '''option''' and '''option end'''.  
 
|-
 
|-
 
|03:52
 
|03:52
Line 121: Line 121:
 
|-
 
|-
 
|04:01
 
|04:01
|We need this echoed once, this echoed once and these echoed for every record in the database or in the table.
+
|We need this echoed once, this echoed once and these echoed for every '''record''' in the '''database''' or in the '''table'''.
 
|-
 
|-
 
|04:10
 
|04:10
Line 136: Line 136:
 
|-
 
|-
 
|04:29
 
|04:29
|So now, presuming everything is alright, we will '''refresh''' and we have a list box of all the first names of the records in our database.
+
|So now, presuming everything is alright, we will '''refresh''' and we have a list box of all the firstnames of the records in our database.
 
|-
 
|-
 
|04:39
 
|04:39
|Now I want to make this look better and so I will say "$surname" or "lastname" in the code.
+
|Now I want to make this look better and so I will say "$surname" or "$lastname" in the code.
 
|-
 
|-
 
|04:47
 
|04:47
|There you go!  Refresh.  This is a really easy way to use html code, is'nt it?
+
|There you go!  '''Refresh'''.  This is a really easy way to use '''html code''', isn't it?
 
|-
 
|-
 
|04:52
 
|04:52
|Now we are going to talk about "option".
+
|Now we are going to talk about '''option'''.
 
|-
 
|-
 
|04:56
 
|04:56
|We need to have a name for each option and the name for each one will be "id".
+
|We need to have a name for each '''option''' and the '''name''' for each one will be "$id".
 
|-
 
|-
 
|05:00
 
|05:00
|If I click on refresh and come on  my page source, you can see that we got 1,2,3,4, in each one here.
+
|If I click on '''refresh''' and come on  my page source, you can see that we got 1,2,3,4, in each one here.
 
|-
 
|-
 
|05:13
 
|05:13
|This is really useful because now we can update, unique records rather than just going by the name.
+
|This is really useful because now we can update unique records rather than just going by the name.
 
|-
 
|-
 
|05:23
 
|05:23
|So  here, I will start to create my update form.
+
|So  here, I will start to create my '''update form'''.
 
|-
 
|-
 
|05:28
 
|05:28
|I will put an input box after my "select", and this is going to be "text".  
+
|I will put an '''input''' box after my "select" and this is going to be "text".  
 
|-
 
|-
 
|05:33
 
|05:33
|The name will be '''to change'''. This is what we are going to change by.
+
|The name will be 'tochange'. This is what we are going to change by.
 
|-
 
|-
 
| 05:40
 
| 05:40
|Next we will create another button or another input element called the '''submit''' button whose value will  be "change".
+
|Next we will create another button or another input element called the '''submit''' button whose value will  be 'change'.
 
|-
 
|-
 
|05:53
 
|05:53
|Here I will just change the first name for now. Just for an example.
+
|Here I will just change the '''$firstname''' for now, just for an example.
 
|-
 
|-
 
|05:58
 
|05:58
|So here is the basis of our form.
+
|So, here is the basis of our '''form'''.
 
|-
 
|-
 
|06:00
 
|06:00
Line 184: Line 184:
 
|-
 
|-
 
|06:12
 
|06:12
|Now what we need to do is put this inside the form so that I can end my form.
+
|Now, what we need to do is put this inside the '''form''' so that I can end my '''form'''.
 
|-
 
|-
 
|06:17
 
|06:17
|Over here, it is getting kind of messy but hopefully you can see whats going on.  
+
|Over here, it is getting kind of messy but hopefully you can see what's going on.  
 
|-
 
|-
 
|06:23
 
|06:23
|Let me scroll down over here.  Up here we need to start our form.
+
|Let me scroll down over here.  Up here, we need to start our '''form'''.
 
|-
 
|-
 
|06:27
 
|06:27
|The action will be the page we are on at the moment which is "mysql dot php".
+
|The '''action''' will be the page we are on at the moment which is "mysql dot php".
 
|-
 
|-
 
|06:33
 
|06:33
|Infact I will do it on another page.  
+
|In fact, I will do it on another page.  
 
|-
 
|-
 
|06:36
 
|06:36
|So rename it to "mysql update dot php".
+
|So, rename it to "mysql update dot php".
 
|-
 
|-
 
|06:40
 
|06:40
Line 214: Line 214:
 
|-
 
|-
 
|07:00
 
|07:00
|We need to start our php tags.
+
|We need to start our '''php tags'''.
 
|-
 
|-
 
|07:03
 
|07:03
Line 223: Line 223:
 
|-
 
|-
 
|07:18
 
|07:18
|So we will call our select name '''peoplename'''.  
+
|So, we will call our '''select name''' '''peoplename'''.  
 
|-
 
|-
 
|07:20
 
|07:20
|So here we will type "peoplename" equals POST and  '''peoplename'''.
+
|So, here we will type "$peoplename" equals $_POST and  'peoplename'.
 
|-
 
|-
 
|07:29
 
|07:29
|That is the name of the html element we are taking.
+
|That is the name of the '''html element''' we are taking.
 
|-
 
|-
 
|07:33
 
|07:33
Line 235: Line 235:
 
|-
 
|-
 
|07:37
 
|07:37
|This is our id which is inside our database.  
+
|This is our '''id''' which is inside our database.  
 
|-
 
|-
 
|07:39
 
|07:39
Line 241: Line 241:
 
|-
 
|-
 
|07:47
 
|07:47
|Here I will code a brief '''if statement''' just to say if '''peoplename''' and '''tochange'''.
+
|Here I will code a brief '''if''' statement just to say '''if''' '''$peoplename AND''' (&&) '''$tochange'''.
 
|-
 
|-
 
|07:56
 
|07:56
Line 247: Line 247:
 
|-  
 
|-  
 
|08:01
 
|08:01
|Then what we will do is type "change" equals "mysql query" and that is simply "UPDATE people", which is the name of our table here.
+
|Then, what we will do is type "$change" equals "mysql_query()" and that is simply "UPDATE people" which is the name of our '''table''' here.
 
|-
 
|-
 
|08:17
 
|08:17
|"UPDATE people SET firstname equals tochange" where "firstname equals"....
+
|'''UPDATE people SET firstname''' equals ''''$tochange' WHERE firstname''' equals....
 
|-
 
|-
 
|08:31
 
|08:31
Line 256: Line 256:
 
|-
 
|-
 
|08:39
 
|08:39
|So we type where the "ID" is equal to the value of the"peoplename".
+
|So we type where the "id" is equal to the value of the $peoplename .
 
|-
 
|-
 
|08:52
 
|08:52
|Right, lets go back.   
+
|Right, let's go back.   
 
|-
 
|-
 
|08:58
 
|08:58
|Lets say I picked "Kyle" to change the name of "Kyle".
+
|Let's say I picked "Kyle" to change the name of "Kyle".
 
|-
 
|-
 
|09:02
 
|09:02
Line 268: Line 268:
 
|-
 
|-
 
|09:06
 
|09:06
|So we are changing this to this where the id is this.
+
|So, we are changing this to this where the '''id''' is this.
 
|-
 
|-
 
|09:11
 
|09:11
Line 274: Line 274:
 
|-
 
|-
 
|09:15
 
|09:15
|So I will see you there soon.  This is Evan Varkey dubbing for the Spoken Tutorial Project. (Script contributed by Juanita Jayakar).
+
|So, I will see you there soon.  This is Evan Varkey dubbing for the Spoken Tutorial Project. (Script contributed by Juanita Jayakar).

Latest revision as of 14:43, 28 October 2020

Time Narration
00:01 In this part of the tutorial, I am going to give you a chance to create a simple program.
00:08 This program will allow us to select a name from a list.
00:15 Also it will allow us to update a piece of information and I am selecting the ability to update the name itself.
00:25 I will say the "firstname" in this, for example.
00:28 Here, we can select from a list and then update that information.
00:33 I will modify this page a little bit to get rid of some information which we do not need.
00:39 We don't need this echoing here.
00:41 We are also going to change our form here, so we don't need this for now.
00:47 Let us delete that.
00:49 We are not going to need this either.
00:52 We will only need the firstname and lastname. Date of birth and gender don't really matter.
00:59 Let us delete this too. We don't need this either.... neither this.
01:04 Ok, there we are.
01:06 This tutorial is not going to be exhaustive and is not going to be completely correct either.
01:13 However, it is going to show you how to apply your records to html select boxes.
01:23 And also showing you how to update information based on what you selected.
01:30 As you see here, I am going to create some data inside the while loop.
01:45 We are going to create some html data here.
01:47 Here I am echoing out. Let me just stop here for the time being.
01:56 Let's go down here.
01:58 We are going to create a select area which is a select box.
02:02 It is a drop down box and for each of these boxes, we have an option.
02:14 For example, this could be 1 or 2.
02:17 So, let's come back here and refresh button. Let's refresh this.
02:28 Let us get rid of this dialog box.
02:31 Here we got 1 or 2. This is the piece of html here.
02:36 Here we are going to apply this and we are going to search for our records. We are going to give a name.... in each of these option boxes.
02:44 I will give an option name to each record that we found.
02:48 If you don't understand this, it means inside the code which is going to be repeated for every record, outside the loop over here, we want to echo the first part of our html code.
03:00 This will be "select" and the name of that is going to be "name".
03:08 Or rather let me call it people name.
03:13 After this, outside of our while loop, here we are going to echo out the ends tag. So, let us type forward slash and select.
03:24 The reason for not incorporating this inside our while loop is because if it is repeating then it is going to repeat the start and the end tags and not the option part which we need.
03:36 Here the option part goes inside the loop.
03:39 Let me echo out, let's say the "$firstname".
03:42 And what this does is, for every record, it is going to echo out this option code.
03:48 And if you remember down here, we had option and option end.
03:52 This is being repeated over and over again.
03:57 Now we have the "select" part here and the "select end" here.
04:01 We need this echoed once, this echoed once and these echoed for every record in the database or in the table.
04:10 You can verify this by refreshing.
04:13 Oh! Where's our code gone?
04:15 Let's go back and find where the mistake is. Actually, we need to change this part here - the if statement.
04:25 We are not looking for our "submit" button anymore, so we can delete that.
04:29 So now, presuming everything is alright, we will refresh and we have a list box of all the firstnames of the records in our database.
04:39 Now I want to make this look better and so I will say "$surname" or "$lastname" in the code.
04:47 There you go! Refresh. This is a really easy way to use html code, isn't it?
04:52 Now we are going to talk about option.
04:56 We need to have a name for each option and the name for each one will be "$id".
05:00 If I click on refresh and come on my page source, you can see that we got 1,2,3,4, in each one here.
05:13 This is really useful because now we can update unique records rather than just going by the name.
05:23 So here, I will start to create my update form.
05:28 I will put an input box after my "select" and this is going to be "text".
05:33 The name will be 'tochange'. This is what we are going to change by.
05:40 Next we will create another button or another input element called the submit button whose value will be 'change'.
05:53 Here I will just change the $firstname for now, just for an example.
05:58 So, here is the basis of our form.
06:00 We have got the "name" here and what we want to change it to.
06:04 So here I will change it from "Alex" to "Alexander" and then click on Change.
06:10 At the moment nothing is happening.
06:12 Now, what we need to do is put this inside the form so that I can end my form.
06:17 Over here, it is getting kind of messy but hopefully you can see what's going on.
06:23 Let me scroll down over here. Up here, we need to start our form.
06:27 The action will be the page we are on at the moment which is "mysql dot php".
06:33 In fact, I will do it on another page.
06:36 So, rename it to "mysql update dot php".
06:40 This will make it a bit easier for you to see and a lot easier for me to write.
06:45 Then by refreshing that, we can see that we go to the new page which isn't found at the moment.
06:52 I am going to create that inside here.
06:55 We will save that straight away as "mysql underscore update dot php".
07:00 We need to start our php tags.
07:03 We need to require our "connect dot php" because we are connecting to our database again.
07:14 We also need to get our value of the name that we are changing.
07:18 So, we will call our select name peoplename.
07:20 So, here we will type "$peoplename" equals $_POST and 'peoplename'.
07:29 That is the name of the html element we are taking.
07:33 This is going to be called 1,2,3.
07:37 This is our id which is inside our database.
07:39 "tochange" is the field in which we have ready to type our new value in.
07:47 Here I will code a brief if statement just to say if $peoplename AND (&&) $tochange.
07:56 This makes sure that we have got both our values there.
08:01 Then, what we will do is type "$change" equals "mysql_query()" and that is simply "UPDATE people" which is the name of our table here.
08:17 UPDATE people SET firstname equals '$tochange' WHERE firstname equals....
08:31 No, in fact we are not..... We are changing it by "id", isn't it?
08:39 So we type where the "id" is equal to the value of the $peoplename .
08:52 Right, let's go back.
08:58 Let's say I picked "Kyle" to change the name of "Kyle".
09:02 The name of this is 2 so the "peoplename" is also 2.
09:06 So, we are changing this to this where the id is this.
09:11 I will show you that in the next part of tutorial because I am running out of time.
09:15 So, I will see you there soon. This is Evan Varkey dubbing for the Spoken Tutorial Project. (Script contributed by Juanita Jayakar).

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sandhya.np14, Sneha