PHP-and-MySQL/C2/Common-Errors-Part-1/English

From Script | Spoken-Tutorial
Revision as of 19:42, 1 December 2012 by Pravin1389 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time Narration
0:00 Hello and welcome. This is more of an explanation video.
0:07 I will go through some of the common errors you might encounter when you are programming in PHP.
0:13 Most of them are self explanatory.
0: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 something out.
0:32 Everyone makes such mistakes - missing either a semicolon or adding an extra bracket or something like that.
0:41 Now I have created a few pages here. These are some of the errors you are likely to encounter.
0:47 There are more. This list isn’t exhaustive. This will just cover some of the basics.
0:51 I have got a context editor ready to take you through each error one by one.
1:00 So the first one I am going to explain is this "html".
1:06 I used a lot of html embedded in our "echo" command here.
1:10 If I try to run this page here, we get this error here.
1:17 It says "Parse error" and we get this message here.
1:20 You really need to look for these - expecting either a comma or a semicolon.
1:25 It gives us a line number. So this will always return a line no. when we get one of these parse errors.
1:32 It says here line 5.
1:36 So if we come down to line 5; you can see here that is line 5 comma 19 (Ln5, Col19); we get all the information.
1:43 Line 5 is here.
1:45 Now there isn’t anything visually wrong with this.
1:50 The way php interprets a command like "echo" is that we get the starting point, our double quotes here and our ending here. So this is will be the start and this will be our end.
2: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.
2:16 I think I have explained this in my echo function tutorial.
2:22 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.
2:31 Now technically, php hasn’t picked this up, so this shouldn’t be here.
2: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.
2:45 But then even after this, it becomes absolute rubbish.
2:51 So what we need to do is use our single quotation marks instead.
2:57 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.
3:06 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.
3:15 And there you go. So you have got that after running our html code. There’s obviously no functionality. But we have covered that.
3:25 Okay so the next one I'm going to do is the semicolon. This is one other common error.
3:30 We go back here and click on semicolon. We have got a parse error here "expecting a semicolon".
3:36 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".
3:43 We are comparing these variables. We need double equals in there.
3:46 If this condition is true, we will echo this message.
3:50 Now if we go here - line no. 9.
3:55 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.
4:01 Now looking at that, there is nothing wrong with line 9.
4:05 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.
4:17 So the code we see here is the same as that.
4:22 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.
4: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.
4:45 We can bring it down here. So let me just re-run this code.
4:50 There you go. So we get a successful page.
4:54 Obviously if I were to put that up here, that would also be a valid code, as would that.
5:01 So php doesn’t work on the basis that "there’s an error on this line".
5:10 It usually says the current line can’t be run may be because of an error on previous line.
5:17 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.
5:29 So that’s two basic errors that we have covered.
5:33 If you ever get things like that, just check and don’t necessarily check the line that the error has been returned on.
5:40 Check before, check after. No, not after but check before and see if you can fix anything.
5:46 Just scan through every single character if you have to.
5:49 I get a lot of emails from people who have made mistakes like that and I don’t mind helping people.
6:01 Feel free to ask, but make sure you check your work once, twice or even thrice before you send me anything.
6:07 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

Chandrika, Pravin1389