Difference between revisions of "PHP-and-MySQL/C2/Common-Errors-Part-1/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(One intermediate revision by one other user not shown)
Line 31: Line 31:
 
|-
 
|-
 
|01:06
 
|01:06
|I used a lot of '''html''' embedded in our '''"echo"''' command here.
+
|I used a lot of '''html''' embedded in our '''echo''' command here.
 
|-
 
|-
 
|01:10
 
|01:10
Line 40: Line 40:
 
|-
 
|-
 
|01:21
 
|01:21
|You really need to look for these - expecting either a comma or a semicolon.  
+
|You really need to look for these - "expecting either a comma or a semicolon".  
 
|-
 
|-
 
|01:27
 
|01:27
|It gives us a line number. So this will always return a line no. when we get one of these '''parse errors'''.
+
|It gives us a line number. So this will always return a line no. when we get one of these '''Parse errors'''.
 
|-
 
|-
 
|01:34
 
|01:34
Line 52: Line 52:
 
|-
 
|-
 
|01:45
 
|01:45
|Line 5 is here.
+
|Line 5 is here. Now there isn’t anything visually wrong with this.
|-
+
|01:46
+
|Now there isn’t anything visually wrong with this.
+
 
|-
 
|-
 
|01:50
 
|01:50
|The way php interprets a command like '''"echo"''' is that we get the starting point, our double quotes here and our ending point here. So this will be the start and this will be our end.
+
|The way php interprets a command like '''echo''' is that we get the starting point, our double quotes here and our ending point here. So this will be the start and this will be our end.
 
|-
 
|-
 
|02:06
 
|02:06
|Now, what’s really happening here is that because we are embedding the 'html', we are using double quotes in between and this means that the '''echo''' '''command''' would be read as starting here and ending here.
+
|Now, what’s really happening here is that because we are embedding the 'html', we are using double quotes in between and this means that the '''echo''' command would be read as starting here and ending here.
 
|-
 
|-
 
|02:17
 
|02:17
Line 82: Line 79:
 
|-
 
|-
 
|02:58
 
|02:58
|Now if I were to '''save''' that, we will now get an '''error''' on line 6 because the '''error''' has come down to it, that changes to 6.
+
|Now if I were to '''save''' that, we will now get an '''error''' on line 6 because the error has come down to it, that changes to 6.
 
|-
 
|-
 
|03:08
 
|03:08
Line 94: Line 91:
 
|-
 
|-
 
|03:33
 
|03:33
|We go back here and click on semicolon. We have got a parse error here "expecting a semicolon".
+
|We go back here and click on '''semicolon'''. We have got a '''parse error''' here "expecting a semicolon".
 
|-
 
|-
 
|03:39
 
|03:39
Line 103: Line 100:
 
|-
 
|-
 
|03:52
 
|03:52
|If this condition is true, we will '''echo''' this message.
+
|If this condition is '''True''', we will '''echo''' this message.
 
|-
 
|-
 
|03:55
 
|03:55
Line 121: Line 118:
 
|-
 
|-
 
|04:23
 
|04:23
|That would actually compile and work but because this is down here and this is the same as up here; we are still expecting a semicolon after that.
+
|That would actually compile and work but because this is down here and this is the same as up here, we are still expecting a semicolon after that.
 
|-
 
|-
 
|04:34
 
|04:34
Line 136: Line 133:
 
|-
 
|-
 
|05:02
 
|05:02
|So '''php''' doesn’t work on the basis that "there’s an error on this line".  
+
|So '''php''' doesn’t work on the basis that there’s an error on this line.  
 
|-
 
|-
 
|05:07
 
|05:07

Latest revision as of 15:48, 24 March 2017

Time Narration
00:00 Hello and welcome. This is more of an explanation to video.
00:07 I will go through some of the common errors you might encounter when you are programming in PHP.
00:13 Most of them are self explanatory.
00:17 I would say a good 50% of errors that you encounter are when you either don't see something you have accidentally typed or you have missed out something.
00:32 Everyone makes such mistakes - missing either a semicolon or adding an extra bracket or something like that.
00:41 Now I have created a few pages here. These are some of the errors you are likely to encounter.
00:47 There are more. This list isn’t exhaustive. This will just cover some of the basics.
00:51 I have got a context editor ready to take you through each error one by one.
01:00 So the first one I am going to explain is this "html".
01:06 I used a lot of html embedded in our echo command here.
01:10 If I try to run this page here, we get this error here.
01:17 It says Parse error and we get this message here.
01:21 You really need to look for these - "expecting either a comma or a semicolon".
01:27 It gives us a line number. So this will always return a line no. when we get one of these Parse errors.
01:34 It says here line 5.
01:36 So, if we come down to line 5 you can see here that is line 5 column 19 (Ln5, Col19); we get all the information.
01:45 Line 5 is here. Now there isn’t anything visually wrong with this.
01:50 The way php interprets a command like echo is that we get the starting point, our double quotes here and our ending point here. So this will be the start and this will be our end.
02:06 Now, what’s really happening here is that because we are embedding the 'html', we are using double quotes in between and this means that the echo command would be read as starting here and ending here.
02:17 I think I have explained this in my echo function tutorial.
02:21 Okay. So the reason that we are getting an error in this line is because this is the first occurrence of a double quotes where it shouldn’t be.
02:31 Now technically, php hasn’t picked this up; so this shouldn’t be here.
02:36 But what it was saying about expecting a semicolon was that when we end an echo, we use a semicolon. So, what it was looking for is that there.
02:49 But then, even after this, it becomes absolute rubbish.
02:52 So, what we need to do is use our single quotation marks instead.
02:58 Now if I were to save that, we will now get an error on line 6 because the error has come down to it, that changes to 6.
03:08 See, you know, you need to change something on line 6 or nearer line 6. You’ll see some of the other ones we will be doing; some don’t return the actual line error.
03:19 And there you go. So you have got that after running our 'html' code. There’s obviously no functionality. But we have covered that.
03:28 Okay. So the next one I'm going to do is the semicolon. This is one other common error.
03:33 We go back here and click on semicolon. We have got a parse error here "expecting a semicolon".
03:39 Now why are we expecting a semicolon? This code looks okay. We have got a variable here with "Alex". We have another variable here with "Alex".
03:47 We are comparing these variables. We need double equals (==) in there.
03:52 If this condition is True, we will echo this message.
03:55 Now if we go here - line no. 9.
03:58 So obviously, this is a very simple code. If it were a bit more complex, you came to line 9 but this is in fact line 9.
04:07 Now looking at that, there is nothing wrong with line 9.
04:10 But in a way, there is something wrong with that line. What we have is the way php interprets the pages; it’s on a single line basis.
04:19 So the code we see here is the same as that.
04:23 That would actually compile and work but because this is down here and this is the same as up here, we are still expecting a semicolon after that.
04:34 If we do this, this is still a valid code. So, I have added a semicolon there, although to the human eye visually it should be there.
04:42 We can bring it down here. So, let me just re-run this code.
04:53 There you go. So we get a successful page.
04:57 Obviously if I were to put that up here, that would also be a valid code as would that.
05:02 So php doesn’t work on the basis that there’s an error on this line.
05:07 It usually says the current line can’t be run may be because of an error on previous line.
05:13 So, because of this error on this line without the semicolon, this line cannot run. Therefore the line has been returned as an error on line 9. You can see that there.
05:29 So that’s two basic errors that we have covered.
05:33 If you ever get things like that, just check and don’t necessarily check the line that the error has been returned on.
05:40 Check before, check after. No, not after but check before and see if you can fix anything.
05:47 Just scan through every single character if you have to.
05:50 I get a lot of emails from people who have made mistakes like that and I don’t mind helping people.
05:56 Feel free to ask but make sure you check your work once, twice or even thrice before you send me anything.
06:04 Okay. So, in the next parts we will cover the rest of the error pages. See you soon. This is Evan Varkey, dubbing for the Spoken Tutorial project. (Script contributed by Antara Atrey)

Contributors and Content Editors

Minal, PoojaMoolya, Pratik kamble, Sandhya.np14