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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
|-
 
|-
 
|00:01
 
|00:01
|Hello Everyone! In the previous tutorial we had selected the data and we successfully displayed the data to our page.
+
|Hello Everyone! In the previous tutorial, we had selected the data and we successfully displayed the data to our page.
 
|-
 
|-
 
|00:09
 
|00:09
|Let me take you back to this page here.We can see that everything is working fine.
+
|Let me take you back to this page here. We can see that everything is working fine.
 
|-
 
|-
 
|00:15
 
|00:15
Line 13: Line 13:
 
|-
 
|-
 
|00:17
 
|00:17
|The next thing we will learn is how to specify somewhere that the user themselves can enter and specify data.  
+
|The next thing we will learn is how to specify somewhere that the users themselves can enter and specify '''data'''.  
 
|-
 
|-
 
|00:23
 
|00:23
|To do this, I will delete all the codes in my page except "connect include".
+
|To do this, I will delete all the code in my page except "connect include".
 
|-
 
|-
 
|00:29
 
|00:29
|If I don't connect to my database, its not going to work.
+
|If I don't connect to my database, it's not going to work.
 
|-
 
|-
 
|00:33
 
|00:33
Line 25: Line 25:
 
|-
 
|-
 
|00:42
 
|00:42
|I will retain firstname,  lastname, date of birth, and gender either male or female.  
+
|I will retain '''firstname''''''lastname''', '''date of birth''' and '''gender'''- either female or male.  
 
|-
 
|-
 
|00:53
 
|00:53
|Below here, I will create a form.  
+
|Below here, I will create a '''form'''.  
 
|-
 
|-
 
|00:55
 
|00:55
|This will be an html form, so we need to start and end our tags.  
+
|This will be an '''html form''', so we need to start and end our '''tags'''.  
 
|-
 
|-
 
|01:03
 
|01:03
|Our "action" will be "mysql dot php" and our "method" is going to be "POST".
+
|Our '''action''' will be "mysql dot php" and our '''method''' is going to be "POST".
 
|-
 
|-
 
|01:13
 
|01:13
Line 40: Line 40:
 
|-
 
|-
 
|01:18
 
|01:18
|For the name we will use our "surname".
+
|For the '''name''' we will use our "surname".
 
|-
 
|-
 
|01:22
 
|01:22
Line 49: Line 49:
 
|-
 
|-
 
|01:30
 
|01:30
|You could even use 2 fields to search.
+
|You could even use 2 '''fields''' to search.
 
|-
 
|-
 
|01:33
 
|01:33
Line 55: Line 55:
 
|-
 
|-
 
|01:40
 
|01:40
|Here I will type "firstname" and I will create an "input" box of type "text " and the "name" of this will be "firstname".
+
|Here I will type "Firstname" and I will create an '''input''' box of '''type''' "text " and the '''name''' of this will be "firstname".
 
|-
 
|-
 
|01:51
 
|01:51
|We will create a break here and type "lastname".  
+
|We will create a '''break''' here and type "Lastname".  
 
|-
 
|-
 
|01:55
 
|01:55
Line 64: Line 64:
 
|-
 
|-
 
|02:03
 
|02:03
|So this line is exactly the same  but instead of "firstname", we type in "lastname".  
+
|So, this line is exactly the same  but instead of "Firstname", we type in "Lastname".  
 
|-
 
|-
 
|02:11
 
|02:11
|We will type "input" type equals "submit" and the "value" of that will be "Get data".
+
|We will type '''input type''' equals "submit" and the '''value''' of that will be "Get data".
 
|-
 
|-
 
|02:21
 
|02:21
|Hence we have taken the "firstname" and "lastname" and the "submit" button.
+
|Hence we have taken the "Firstname" and "Lastname" and the "submit" button.
 
|-
 
|-
 
|02:25
 
|02:25
|If I refresh this, we can see "Firstname" and "Lastname" has appeared.
+
|If I refresh this, we can see "Firstname" and "Lastname" have appeared.
 
|-
 
|-
 
|02:29
 
|02:29
|I will delete this for now and to do this I will check if the "submit" button has been pressed.
+
|I will delete this for now and to do this, I will check if the "submit" button has been pressed.
 
|-
 
|-
 
|02:37
 
|02:37
Line 82: Line 82:
 
|-
 
|-
 
|02:41
 
|02:41
|Then I will type in an "if" statement - "if dollar underscore POST submit".  
+
|Then I will type in an '''if''' statement - '''if''' dollar underscore '''POST''' 'submit'.  
 
|-
 
|-
 
|02:51
 
|02:51
Line 91: Line 91:
 
|-
 
|-
 
|03:02
 
|03:02
|This is after this curly bracket here because that is a part of our "while" statement here.
+
|This is after this curly bracket here because that is a part of our '''while''' statement here.
 
|-
 
|-
 
|03:07
 
|03:07
|We don't actually need our while statement for this.  But I will still keep it for the sake of it.
+
|We don't actually need our '''while''' statement for this.  But I will still keep it for the sake of it.
 
|-
 
|-
 
|03:22
 
|03:22
|I will now type "grab POST data" and "dollar firstname".
+
|I will now type "grab POST data" and dollar '''firstname'''.
 
|-
 
|-
 
|03:29
 
|03:29
|So this is "dollar underscore POST firstname" and then I will type "lastname".
+
|So this is dollar underscore '''POST''' 'firstname' and then I will type 'lastname'.
 
|-
 
|-
 
|03:35
 
|03:35
|I will copy "firstname" and paste it here and change it to "lastname".
+
|I will copy 'firstname' and paste it here and change it to 'lastname'.
 
|-
 
|-
 
|03:43
 
|03:43
|So we have got our "firstname" and "lastname".
+
|So we have got our 'firstname' and 'lastname'.
 
|-
 
|-
 
|03:49
 
|03:49
|I will type "echo" and this message "Record for firstname" . On second thoughts, let us not do this at the moment.
+
|I will type: '''echo''' and this message '''Record for $firstname''' . On second thoughts, let us not do this at the moment.
 
|-
 
|-
 
|04:02
 
|04:02
|I will go straight to my query here.
+
|I will go straight to my '''query''' here.
 
|-
 
|-
 
|04:05
 
|04:05
Line 118: Line 118:
 
|-
 
|-
 
|04:10
 
|04:10
|For this, I will type "SELECT star FROM people WHERE firstname equals Alex and lastname equals Garrett".
+
|For this, I will type '''SELECT''' star '''FROM people WHERE firstname''' equals 'Alex' and '''lastname''' equals 'Garrett'.
 
|-
 
|-
 
|04:29
 
|04:29
Line 124: Line 124:
 
|-
 
|-
 
|04:39
 
|04:39
|I had shown it in the update  where we can update where the firstname equals "Alex" and the lastname equals "Garrett".
+
|I had shown it in the update  where we can update where the '''firstname''' equals "Alex" and the '''lastname''' equals "Garrett".
 
|-
 
|-
 
|04:48
 
|04:48
|Now we will select everything we want from our table here and we will say select everything where our firstname is Alex to lastname is Garrett.
+
|Now we will select everything we want from our table here and we will say- select everything where our '''firstname''' is 'Alex' to '''lastname''' is 'Garrett'.
 
|-
 
|-
 
|04:57
 
|04:57
|If we look at our database here, we are searching for our firstname and matching it to "Alex", searching the surname and matching it to "Garrett".
+
|If we look at our database here, we are searching for our '''firstname''' and matching it to "Alex", searching the surname and matching it to "Garrett".
 
|-
 
|-
 
|05:07
 
|05:07
Line 136: Line 136:
 
|-
 
|-
 
|05:15
 
|05:15
|From the date of birth to gender, my id to my firstname and lastname.
+
|From the '''date of birth''' to '''gender''', my '''id''' to my '''firstname''' and '''lastname'''.
 
|-
 
|-
 
|05:19
 
|05:19
|So we have understood that this will select only one record at this time, therefore we don't need to order by the "id".   
+
|So we have understood that this will select only one '''record''' at this time, therefore we don't need to order by the "id".   
 
|-
 
|-
 
|05:27
 
|05:27
Line 148: Line 148:
 
|-
 
|-
 
|05:35
 
|05:35
|Ok so we are running our loop, we are selecting each part of data here and we are changing our male to "male" and female to "female".  
+
|Ok, so we are running our loop, we are selecting each part of data here and we are changing our male to "Male" and female to "Female".  
 
|-
 
|-
 
|05:43
 
|05:43
Line 154: Line 154:
 
|-
 
|-
 
|05:52
 
|05:52
|Then we are only going to echo out the firstname and the lastname over here that has been found, which is my first and lastname but by changing "Alex" here to "firstname" which is here.
+
|Then we are only going to '''echo''' out the '''firstname''' and the '''lastname''' over here that has been found which is my first and lastname but by changing "Alex" here to '''$firstname''' which is here.
 
|-
 
|-
 
|06:04
 
|06:04
Line 160: Line 160:
 
|-
 
|-
 
|06:08
 
|06:08
|We have the "firstname" and so here, I will name this as "firstname underscore form" and "lastname underscore form"  
+
|We have the "firstname" and so here, I will name this as "$firstname underscore form" and "$lastname underscore form"  
 
|-
 
|-
 
|06:15
 
|06:15
|We will select from where the firstname has been posted equal to this and the lastname that we posted equal to lastname form.
+
|We will select from where the firstname has been posted equal to this and the lastname that we posted equal to lastname_form.
 
|-
 
|-
 
|06:26
 
|06:26
| So This is the data that's come from our form.
+
| So, this is the data that's come from our '''form'''.
 
|-
 
|-
 
|06:29
 
|06:29
|so if I were to type "Alex Garrett" in my html form and submit it then this will equal "Alex" and this will equal "Garrett".
+
|So, if I were to type "Alex Garrett" in my '''html form''' and submit it then this will equal 'Alex' and this will equal 'Garrett'.
 
|-
 
|-
 
|06:38
 
|06:38
Line 175: Line 175:
 
|-
 
|-
 
|06:44
 
|06:44
|So it will take all the data for "Alex Garrett" and check for female or male and then echo out this particular message.
+
|So, it will take all the data for "Alex Garrett" and check for 'Female' or 'Male' and then '''echo''' out this particular message.
 
|-
 
|-
 
|06:51
 
|06:51
|So if I come here and refresh at the moment there is nothing because no data has been specified in these form variables here.
+
|So, if I come here and '''refresh''', at the moment there is nothing because no data has been specified in these '''form''' variables here.
 
|-
 
|-
 
|07:01
 
|07:01
|Let me show you. These are empty therefore we are selecting "star" from people under this condition "WHERE the name equals to nothing and the lastname equals to nothing".
+
|Let me show you. These are empty. Therefore we are selecting star from '''people''' under this condition '''WHERE''' the '''name''' equals to nothing and the '''lastname''' equals to nothing.
 
|-
 
|-
 
|07:12
 
|07:12
|That has not returned any data at the moment because what we got in our firstname and lastname are actual peoples names.
+
|That has not returned any data at the moment because what we got in our '''firstname''' and '''lastname''' are actual people's names.
 
|-
 
|-
 
|07:24
 
|07:24
|Anyway now I will just type in a completely random name.
+
|Anyway, now I will just type in a completely random name.
 
|-
 
|-
 
|07:28
 
|07:28
|So lets say "David Green" and click get data and nothing has happened, ok?
+
|So let's say "David Green" and click '''Get data''' and nothing has happened, ok?
 
|-
 
|-
 
|07:36
 
|07:36
Line 196: Line 196:
 
|-
 
|-
 
|07:49
 
|07:49
|I go back here and say "David Green" and click get data and oh! we don't have an error!
+
|I go back here and say "David Green" and click '''Get data''' and oh! we don't have an error!
 
|-
 
|-
 
|07:57
 
|07:57
|Oh yes that's because the structure of the sql code correct and so we don't get any error.
+
|Oh yes!! That's because the structure of the '''sql code''' correct and so we don't get any error.
 
|-
 
|-
 
|08:03
 
|08:03
Line 205: Line 205:
 
|-
 
|-
 
|08:05
 
|08:05
|Now lets suppose that we do have a name that's in our database.
+
|Now let's suppose that we do have a name that's in our database.
 
|-
 
|-
 
|08:10
 
|08:10
|Lets say "Alex Garrett" and we click "Get data".
+
|Let's say "Alex Garrett" and we click "Get data".
 
|-
 
|-
 
|08:13
 
|08:13
|We are presented here with alex garrett was bron blah blah blah and is male.
+
|We are presented here with "Alex Garrett was born blah blah blah and is Male".
 
|-
 
|-
 
|08:20
 
|08:20
|Lets type "Dale Garrett" and click "Get data" and we receive that information from the database.
+
|Let's type "Dale Garrett" and click "Get data" and we receive that information from the database.
 
|-
 
|-
 
|08:26
 
|08:26
|So you can see that this is very useful to incorporate forms into our data.
+
|So, you can see that this is very useful to incorporate '''forms''' into our data.
 
|-
 
|-
 
|08:32
 
|08:32
|I will stop here and go on to the next part where I will be talking about how to update records using this method.
+
|I will stop here and go on to the next part where I will be talking about how to update '''records''' using this method.
 
|-
 
|-
 
|08:40
 
|08:40
|Many of you would be able to do that on your own by now but I will take you through it anyways along with a few other useful things.
+
|Many of you would be able to do that on your own by now but I will take you through it anyway along with a few other useful things.
 
|-
 
|-
 
|08:48
 
|08:48
|Ok so, see you soon.  This is Evan Varkey dubbing for the Spoken Tutorial Project. (Script contributed by Juanita Jayakar).
+
|Ok so, see you soon.  This is Evan Varkey, dubbing for the Spoken Tutorial Project. (Script contributed by Juanita Jayakar).

Latest revision as of 21:29, 1 June 2015

Time Narration
00:01 Hello Everyone! In the previous tutorial, we had selected the data and we successfully displayed the data to our page.
00:09 Let me take you back to this page here. We can see that everything is working fine.
00:15 We have all our data here.
00:17 The next thing we will learn is how to specify somewhere that the users themselves can enter and specify data.
00:23 To do this, I will delete all the code in my page except "connect include".
00:29 If I don't connect to my database, it's not going to work.
00:33 There is a lot of extracting and some other things to be found.
00:42 I will retain firstname, lastname, date of birth and gender- either female or male.
00:53 Below here, I will create a form.
00:55 This will be an html form, so we need to start and end our tags.
01:03 Our action will be "mysql dot php" and our method is going to be "POST".
01:13 Here we will create a form in which the user can specify a name.
01:18 For the name we will use our "surname".
01:22 You can use any one of them. For example, your date of birth or gender to search.
01:28 It is your choice.
01:30 You could even use 2 fields to search.
01:33 I will now show you how to use 2 fields so that you know that it is not very complicated but easy.
01:40 Here I will type "Firstname" and I will create an input box of type "text " and the name of this will be "firstname".
01:51 We will create a break here and type "Lastname".
01:55 Next we will create another input box by copying the previous line and pasting it here.
02:03 So, this line is exactly the same but instead of "Firstname", we type in "Lastname".
02:11 We will type input type equals "submit" and the value of that will be "Get data".
02:21 Hence we have taken the "Firstname" and "Lastname" and the "submit" button.
02:25 If I refresh this, we can see "Firstname" and "Lastname" have appeared.
02:29 I will delete this for now and to do this, I will check if the "submit" button has been pressed.
02:37 To do this, I will first name the "submit" button as "submit".
02:41 Then I will type in an if statement - if dollar underscore POST 'submit'.
02:51 If the submit button has been pressed, start the block.
02:55 This is the block of code to be executed and we end our block where we want this to end.
03:02 This is after this curly bracket here because that is a part of our while statement here.
03:07 We don't actually need our while statement for this. But I will still keep it for the sake of it.
03:22 I will now type "grab POST data" and dollar firstname.
03:29 So this is dollar underscore POST 'firstname' and then I will type 'lastname'.
03:35 I will copy 'firstname' and paste it here and change it to 'lastname'.
03:43 So we have got our 'firstname' and 'lastname'.
03:49 I will type: echo and this message Record for $firstname . On second thoughts, let us not do this at the moment.
04:02 I will go straight to my query here.
04:05 If you remember, I had mentioned that you can specify what data you want in particular.
04:10 For this, I will type SELECT star FROM people WHERE firstname equals 'Alex' and lastname equals 'Garrett'.
04:29 I had not shown this inside this piece of query where we are selecting.
04:39 I had shown it in the update where we can update where the firstname equals "Alex" and the lastname equals "Garrett".
04:48 Now we will select everything we want from our table here and we will say- select everything where our firstname is 'Alex' to lastname is 'Garrett'.
04:57 If we look at our database here, we are searching for our firstname and matching it to "Alex", searching the surname and matching it to "Garrett".
05:07 We are selecting this whole row of data over here which is highlighted in pink at the moment and we are just selecting the whole data from here.
05:15 From the date of birth to gender, my id to my firstname and lastname.
05:19 So we have understood that this will select only one record at this time, therefore we don't need to order by the "id".
05:27 But I will keep it like that anyway, since there is only one record.
05:31 Ordering is not an issue, so we can just leave it that way.
05:35 Ok, so we are running our loop, we are selecting each part of data here and we are changing our male to "Male" and female to "Female".
05:43 The echoing out our data based on this query because this data based query is specific to my first and surname.
05:52 Then we are only going to echo out the firstname and the lastname over here that has been found which is my first and lastname but by changing "Alex" here to $firstname which is here.
06:04 Now that's a repetition. This is a double variable here.
06:08 We have the "firstname" and so here, I will name this as "$firstname underscore form" and "$lastname underscore form"
06:15 We will select from where the firstname has been posted equal to this and the lastname that we posted equal to lastname_form.
06:26 So, this is the data that's come from our form.
06:29 So, if I were to type "Alex Garrett" in my html form and submit it then this will equal 'Alex' and this will equal 'Garrett'.
06:38 Our query will return only one result because at the moment we have only one person named "Alex Garrett".
06:44 So, it will take all the data for "Alex Garrett" and check for 'Female' or 'Male' and then echo out this particular message.
06:51 So, if I come here and refresh, at the moment there is nothing because no data has been specified in these form variables here.
07:01 Let me show you. These are empty. Therefore we are selecting star from people under this condition WHERE the name equals to nothing and the lastname equals to nothing.
07:12 That has not returned any data at the moment because what we got in our firstname and lastname are actual people's names.
07:24 Anyway, now I will just type in a completely random name.
07:28 So let's say "David Green" and click Get data and nothing has happened, ok?
07:36 If we had an error message at the end over here, this is our query written over here, I could say "or die mysql error".
07:49 I go back here and say "David Green" and click Get data and oh! we don't have an error!
07:57 Oh yes!! That's because the structure of the sql code correct and so we don't get any error.
08:03 I was just testing that out.
08:05 Now let's suppose that we do have a name that's in our database.
08:10 Let's say "Alex Garrett" and we click "Get data".
08:13 We are presented here with "Alex Garrett was born blah blah blah and is Male".
08:20 Let's type "Dale Garrett" and click "Get data" and we receive that information from the database.
08:26 So, you can see that this is very useful to incorporate forms into our data.
08:32 I will stop here and go on to the next part where I will be talking about how to update records using this method.
08:40 Many of you would be able to do that on your own by now but I will take you through it anyway along with a few other useful things.
08:48 Ok so, see you soon. This is Evan Varkey, dubbing for the Spoken Tutorial Project. (Script contributed by Juanita Jayakar).

Contributors and Content Editors

Gaurav, Pratik kamble, Sandhya.np14, Sneha