Difference between revisions of "PHP-and-MySQL/C2/Common-Errors-Part-2/English-timed"
From Script | Spoken-Tutorial
(Created page with '{| border=1 !Time !Narration |- |0:00 |Hello again. Welcome to the second part of our error tutorial on how to spot errors and how to fix them. |- |0:08 |I have called this "ext…') |
PoojaMoolya (Talk | contribs) |
||
Line 3: | Line 3: | ||
!Narration | !Narration | ||
|- | |- | ||
− | | | + | |00:00 |
|Hello again. Welcome to the second part of our error tutorial on how to spot errors and how to fix them. | |Hello again. Welcome to the second part of our error tutorial on how to spot errors and how to fix them. | ||
|- | |- | ||
− | | | + | |00:08 |
|I have called this "extrachar dot php" and the reason is that when we run this, ...lets go back, ...click on "extrachar", we get this error "Parse error in" and all of this and on line 6. | |I have called this "extrachar dot php" and the reason is that when we run this, ...lets go back, ...click on "extrachar", we get this error "Parse error in" and all of this and on line 6. | ||
|- | |- | ||
− | | | + | |00:23 |
|We are given no information what-so-ever as to what we are expecting or what we are not expecting or anything of that sort. | |We are given no information what-so-ever as to what we are expecting or what we are not expecting or anything of that sort. | ||
|- | |- | ||
− | | | + | |00:32 |
|We jump to line 6 which is here and at first glance this might look okay. | |We jump to line 6 which is here and at first glance this might look okay. | ||
|- | |- | ||
− | | | + | |00:37 |
|But we have actually got an extra bracket on here so we are deleting that and you can see this now works. | |But we have actually got an extra bracket on here so we are deleting that and you can see this now works. | ||
|- | |- | ||
− | | | + | |00:44 |
|And now that's pretty easy to spot. | |And now that's pretty easy to spot. | ||
|- | |- | ||
− | | | + | |00:47 |
|However when you are doing things like mathematical calculations for example like adding, comparing, etc.. if you are doing mathematical calculations like this and you lose track of your brackets. | |However when you are doing things like mathematical calculations for example like adding, comparing, etc.. if you are doing mathematical calculations like this and you lose track of your brackets. | ||
|- | |- | ||
− | | | + | |01:09 |
|Sometimes it is very easy to solve. When we run this, nothing is going to come up because these two don’t equal each other. | |Sometimes it is very easy to solve. When we run this, nothing is going to come up because these two don’t equal each other. | ||
|- | |- | ||
− | | | + | |01:18 |
|That didn't return any errors. | |That didn't return any errors. | ||
|- | |- | ||
− | | | + | |01:20 |
|But if I add an extra bracket here, we'll get a "Parse error". | |But if I add an extra bracket here, we'll get a "Parse error". | ||
|- | |- | ||
− | | | + | |01:28 |
|When you solve complicated if statements or complex mathematical operations, you should check that the brackets match. | |When you solve complicated if statements or complex mathematical operations, you should check that the brackets match. | ||
|- | |- | ||
− | | | + | |01:36 |
|Just make sure that you are checking for all the brackets or anything else like some characters that seem to be in there. | |Just make sure that you are checking for all the brackets or anything else like some characters that seem to be in there. | ||
|- | |- | ||
− | | | + | |01:48 |
|For example - lets put an "a" in front of that. | |For example - lets put an "a" in front of that. | ||
|- | |- | ||
− | | | + | |01:52 |
|See - when we go back we still get a "Parse error". | |See - when we go back we still get a "Parse error". | ||
|- | |- | ||
− | | | + | |01:56 |
|Lets get rid of this. Refresh that, still getting a "Parse error". | |Lets get rid of this. Refresh that, still getting a "Parse error". | ||
|- | |- | ||
− | | | + | |02:00 |
|So you know you might have typed something. Lets remove that. | |So you know you might have typed something. Lets remove that. | ||
|- | |- | ||
− | | | + | |02:04 |
|Okay now the next one I will show is the "missing page". | |Okay now the next one I will show is the "missing page". | ||
|- | |- | ||
− | | | + | |02:08 |
|Let me show you the error for this. Click on "missing.php". Ok we get more Parse errors as seen on line 9. | |Let me show you the error for this. Click on "missing.php". Ok we get more Parse errors as seen on line 9. | ||
|- | |- | ||
− | | | + | |02:17 |
|Lets go down and where is line 9? Semicolon. | |Lets go down and where is line 9? Semicolon. | ||
|- | |- | ||
− | | | + | |02:23 |
|Okay sorry that was actually not intended. So lets refresh again. | |Okay sorry that was actually not intended. So lets refresh again. | ||
|- | |- | ||
− | | | + | |02:28 |
|Okay. So we have got a "Parse error" on line 18. | |Okay. So we have got a "Parse error" on line 18. | ||
|- | |- | ||
− | | | + | |02:33 |
|Lets go to line 18. | |Lets go to line 18. | ||
|- | |- | ||
− | | | + | |02:37 |
|Okay now - line 18 - this line here where I am pointing is line 18. | |Okay now - line 18 - this line here where I am pointing is line 18. | ||
|- | |- | ||
− | | | + | |02:47 |
|So what is wrong with line 18? | |So what is wrong with line 18? | ||
|- | |- | ||
− | | | + | |02:49 |
|There is absolutely no content on line 18. How could we possibly have an error? | |There is absolutely no content on line 18. How could we possibly have an error? | ||
|- | |- | ||
− | | | + | |02:54 |
|And the reason for that is what I said earlier - to check around this area. | |And the reason for that is what I said earlier - to check around this area. | ||
|- | |- | ||
− | | | + | |03:00 |
|So we have to check a couple of lines up - say 4 or 5 lines up. | |So we have to check a couple of lines up - say 4 or 5 lines up. | ||
|- | |- | ||
− | | | + | |03:06 |
|What we have is an "if" statement - "if posted user name equals 'Alex'", echo "You own PHP Academy", else echo "Hello name". | |What we have is an "if" statement - "if posted user name equals 'Alex'", echo "You own PHP Academy", else echo "Hello name". | ||
|- | |- | ||
− | | | + | |03:17 |
|We might say that we have got a starting curly bracket and an ending curly bracket for this "if" statement here. | |We might say that we have got a starting curly bracket and an ending curly bracket for this "if" statement here. | ||
|- | |- | ||
− | | | + | |03:24 |
|Why isn’t it working? That's because we have already started an "if" statement up here. | |Why isn’t it working? That's because we have already started an "if" statement up here. | ||
|- | |- | ||
− | | | + | |03:30 |
|And this is the purpose of indentation and the usefulness of indentation. | |And this is the purpose of indentation and the usefulness of indentation. | ||
|- | |- | ||
− | | | + | |03:36 |
|To me when I look at this from experience, I know that since this bracket is indented , that bracket should be indented here, in the same line. | |To me when I look at this from experience, I know that since this bracket is indented , that bracket should be indented here, in the same line. | ||
|- | |- | ||
− | | | + | |03:45 |
|Therefore it is missing. So if this was there and that was indented here, then I would know that's from the previous "if" statement up here where the block starts here and the block ends here. | |Therefore it is missing. So if this was there and that was indented here, then I would know that's from the previous "if" statement up here where the block starts here and the block ends here. | ||
|- | |- | ||
− | | | + | |03:59 |
|But here, the block starts here and there is no end bracket here. | |But here, the block starts here and there is no end bracket here. | ||
|- | |- | ||
− | | | + | |04:03 |
|I'll put it here. And when we run this, there you go! It starts working now. | |I'll put it here. And when we run this, there you go! It starts working now. | ||
|- | |- | ||
− | | | + | |04:08 |
|So if you miss out characters, you will find that you get weird places for the errors. | |So if you miss out characters, you will find that you get weird places for the errors. | ||
|- | |- | ||
− | | | + | |04:14 |
|In fact, this is not a weird place for the error because we are saying "else", start of block and end of block. | |In fact, this is not a weird place for the error because we are saying "else", start of block and end of block. | ||
|- | |- | ||
− | | | + | |04:20 |
|And what we are looking for is an end to this block now because this is the block that hasn’t been ended. | |And what we are looking for is an end to this block now because this is the block that hasn’t been ended. | ||
|- | |- | ||
− | | | + | |04:28 |
|So we are saying the line error is not actually here because we require an end to a block here. | |So we are saying the line error is not actually here because we require an end to a block here. | ||
|- | |- | ||
− | | | + | |04:35 |
|Now that will work, okay? | |Now that will work, okay? | ||
|- | |- | ||
− | | | + | |04:38 |
|So just look around couple of lines up and see where you might have an else without an end or some other character missing or something else that you require that's missing. | |So just look around couple of lines up and see where you might have an else without an end or some other character missing or something else that you require that's missing. | ||
|- | |- | ||
− | | | + | |04:49 |
|Next lets switch to the "getpost dot php". | |Next lets switch to the "getpost dot php". | ||
|- | |- | ||
− | | | + | |04:53 |
|I have used the error-reporting "E All" just to demonstrate this. | |I have used the error-reporting "E All" just to demonstrate this. | ||
|- | |- | ||
Line 135: | Line 135: | ||
|This is to "demonstrate". This type of error is going to be reported. | |This is to "demonstrate". This type of error is going to be reported. | ||
|- | |- | ||
− | | | + | |05:03 |
|This doesn't mean all errors. Its not an exhaustive list of all the errors that can be reported. | |This doesn't mean all errors. Its not an exhaustive list of all the errors that can be reported. | ||
|- | |- | ||
− | | | + | |05:10 |
|This is just a parameter for this function. | |This is just a parameter for this function. | ||
|- | |- | ||
− | | | + | |05:12 |
|This will allow us to see some errors that the user wouldn’t usually say. I mean you wouldn’t use this if you were to launch your own website. But I have a tutorial on this which you should see. | |This will allow us to see some errors that the user wouldn’t usually say. I mean you wouldn’t use this if you were to launch your own website. But I have a tutorial on this which you should see. | ||
|- | |- | ||
− | | | + | |05:25 |
|So, this is a "get post" error. | |So, this is a "get post" error. | ||
|- | |- | ||
− | | | + | |05:28 |
|Lets go here. Ok, so we have got a variable called "data". | |Lets go here. Ok, so we have got a variable called "data". | ||
|- | |- | ||
− | | | + | |05:33 |
|This is the GET variable called "name". | |This is the GET variable called "name". | ||
|- | |- | ||
− | | | + | |05:38 |
|Our code says "if this data variable exists, echo data" and this seems like a pretty normal program. | |Our code says "if this data variable exists, echo data" and this seems like a pretty normal program. | ||
|- | |- | ||
− | | | + | |05:47 |
|There is no actual error here. | |There is no actual error here. | ||
|- | |- | ||
− | | | + | |05:49 |
|We are taking some variable here and everything is working and there is no line break error or line terminating error, either. | |We are taking some variable here and everything is working and there is no line break error or line terminating error, either. | ||
|- | |- | ||
− | | | + | |06:07 |
|We have not missed anything, we don’t need to put anything in. | |We have not missed anything, we don’t need to put anything in. | ||
|- | |- | ||
− | | | + | |06:15 |
|But when I run this page, we get a notice. | |But when I run this page, we get a notice. | ||
|- | |- | ||
− | | | + | |06:18 |
|Now this is not a "Parse error" which you have seen before. This is a notice. | |Now this is not a "Parse error" which you have seen before. This is a notice. | ||
|- | |- | ||
− | | | + | |06:27 |
|And the page can’t function properly with this error present. | |And the page can’t function properly with this error present. | ||
|- | |- | ||
− | | | + | |06:33 |
|Let me show you - here I say "name equals alex" and this error disappears. | |Let me show you - here I say "name equals alex" and this error disappears. | ||
|- | |- | ||
− | | | + | |06:41 |
|This shows that there is nothing really wrong with our code but what was wrong in first place, was that this data variable had not been fulfilled. | |This shows that there is nothing really wrong with our code but what was wrong in first place, was that this data variable had not been fulfilled. | ||
|- | |- | ||
− | | | + | |06:51 |
|It's the same as saying "data equals absolutely nothing". | |It's the same as saying "data equals absolutely nothing". | ||
|- | |- | ||
− | | | + | |06:58 |
|Here let me say "echo variable alex" and this is line 5. | |Here let me say "echo variable alex" and this is line 5. | ||
|- | |- | ||
− | | | + | |07:05 |
|Lets refresh. Undefined variable alex, Undefined index name. | |Lets refresh. Undefined variable alex, Undefined index name. | ||
|- | |- | ||
− | | | + | |07:11 |
|So what we are doing is - okay, let me start from the beginning. | |So what we are doing is - okay, let me start from the beginning. | ||
|- | |- | ||
− | | | + | |07:19 |
|This is unfulfilled if the name has not been specified in the header. | |This is unfulfilled if the name has not been specified in the header. | ||
|- | |- | ||
− | | | + | |07:23 |
|Therefore "data equals nothing" and so we get the error "Undefined index", just like we get "Undefined variable" if we echo a variable that hasn't been set. | |Therefore "data equals nothing" and so we get the error "Undefined index", just like we get "Undefined variable" if we echo a variable that hasn't been set. | ||
|- | |- | ||
− | | | + | |07:35 |
|So as soon as we put some data in here, this error goes. | |So as soon as we put some data in here, this error goes. | ||
|- | |- | ||
− | | | + | |07:39 |
|Lets refresh . | |Lets refresh . | ||
|- | |- | ||
− | | | + | |07:41 |
|If you want to get rid of this initial error all you need to do is put a "@ (at)" symbol in between or at the start of this line. | |If you want to get rid of this initial error all you need to do is put a "@ (at)" symbol in between or at the start of this line. | ||
|- | |- | ||
− | | | + | |07:50 |
|When we refresh, we get nothing because no error has been set. | |When we refresh, we get nothing because no error has been set. | ||
|- | |- | ||
− | | | + | |07:55 |
|No get variable has been set. And as soon as we say "name equals alex" our name is echoed out just like the code here specifies. | |No get variable has been set. And as soon as we say "name equals alex" our name is echoed out just like the code here specifies. | ||
|- | |- | ||
− | | | + | |08:04 |
|So even though you are using this "if data exists", technically this still doesn’t exist, if nothing has been put here. So look out for them. | |So even though you are using this "if data exists", technically this still doesn’t exist, if nothing has been put here. So look out for them. | ||
|- | |- | ||
− | | | + | |08:14 |
|That's all for now. In the last part, I will go through the next two common errors quickly. See you there. | |That's all for now. In the last part, I will go through the next two common errors quickly. See you there. | ||
|- | |- | ||
− | | | + | |08:20 |
|This is Evan Varkey dubbing for the Spoken Tutorial project. | |This is Evan Varkey dubbing for the Spoken Tutorial project. | ||
Thanks for watching . | Thanks for watching . |
Revision as of 12:02, 1 September 2014
Time | Narration |
---|---|
00:00 | Hello again. Welcome to the second part of our error tutorial on how to spot errors and how to fix them. |
00:08 | I have called this "extrachar dot php" and the reason is that when we run this, ...lets go back, ...click on "extrachar", we get this error "Parse error in" and all of this and on line 6. |
00:23 | We are given no information what-so-ever as to what we are expecting or what we are not expecting or anything of that sort. |
00:32 | We jump to line 6 which is here and at first glance this might look okay. |
00:37 | But we have actually got an extra bracket on here so we are deleting that and you can see this now works. |
00:44 | And now that's pretty easy to spot. |
00:47 | However when you are doing things like mathematical calculations for example like adding, comparing, etc.. if you are doing mathematical calculations like this and you lose track of your brackets. |
01:09 | Sometimes it is very easy to solve. When we run this, nothing is going to come up because these two don’t equal each other. |
01:18 | That didn't return any errors. |
01:20 | But if I add an extra bracket here, we'll get a "Parse error". |
01:28 | When you solve complicated if statements or complex mathematical operations, you should check that the brackets match. |
01:36 | Just make sure that you are checking for all the brackets or anything else like some characters that seem to be in there. |
01:48 | For example - lets put an "a" in front of that. |
01:52 | See - when we go back we still get a "Parse error". |
01:56 | Lets get rid of this. Refresh that, still getting a "Parse error". |
02:00 | So you know you might have typed something. Lets remove that. |
02:04 | Okay now the next one I will show is the "missing page". |
02:08 | Let me show you the error for this. Click on "missing.php". Ok we get more Parse errors as seen on line 9. |
02:17 | Lets go down and where is line 9? Semicolon. |
02:23 | Okay sorry that was actually not intended. So lets refresh again. |
02:28 | Okay. So we have got a "Parse error" on line 18. |
02:33 | Lets go to line 18. |
02:37 | Okay now - line 18 - this line here where I am pointing is line 18. |
02:47 | So what is wrong with line 18? |
02:49 | There is absolutely no content on line 18. How could we possibly have an error? |
02:54 | And the reason for that is what I said earlier - to check around this area. |
03:00 | So we have to check a couple of lines up - say 4 or 5 lines up. |
03:06 | What we have is an "if" statement - "if posted user name equals 'Alex'", echo "You own PHP Academy", else echo "Hello name". |
03:17 | We might say that we have got a starting curly bracket and an ending curly bracket for this "if" statement here. |
03:24 | Why isn’t it working? That's because we have already started an "if" statement up here. |
03:30 | And this is the purpose of indentation and the usefulness of indentation. |
03:36 | To me when I look at this from experience, I know that since this bracket is indented , that bracket should be indented here, in the same line. |
03:45 | Therefore it is missing. So if this was there and that was indented here, then I would know that's from the previous "if" statement up here where the block starts here and the block ends here. |
03:59 | But here, the block starts here and there is no end bracket here. |
04:03 | I'll put it here. And when we run this, there you go! It starts working now. |
04:08 | So if you miss out characters, you will find that you get weird places for the errors. |
04:14 | In fact, this is not a weird place for the error because we are saying "else", start of block and end of block. |
04:20 | And what we are looking for is an end to this block now because this is the block that hasn’t been ended. |
04:28 | So we are saying the line error is not actually here because we require an end to a block here. |
04:35 | Now that will work, okay? |
04:38 | So just look around couple of lines up and see where you might have an else without an end or some other character missing or something else that you require that's missing. |
04:49 | Next lets switch to the "getpost dot php". |
04:53 | I have used the error-reporting "E All" just to demonstrate this. |
4:58 | This is to "demonstrate". This type of error is going to be reported. |
05:03 | This doesn't mean all errors. Its not an exhaustive list of all the errors that can be reported. |
05:10 | This is just a parameter for this function. |
05:12 | This will allow us to see some errors that the user wouldn’t usually say. I mean you wouldn’t use this if you were to launch your own website. But I have a tutorial on this which you should see. |
05:25 | So, this is a "get post" error. |
05:28 | Lets go here. Ok, so we have got a variable called "data". |
05:33 | This is the GET variable called "name". |
05:38 | Our code says "if this data variable exists, echo data" and this seems like a pretty normal program. |
05:47 | There is no actual error here. |
05:49 | We are taking some variable here and everything is working and there is no line break error or line terminating error, either. |
06:07 | We have not missed anything, we don’t need to put anything in. |
06:15 | But when I run this page, we get a notice. |
06:18 | Now this is not a "Parse error" which you have seen before. This is a notice. |
06:27 | And the page can’t function properly with this error present. |
06:33 | Let me show you - here I say "name equals alex" and this error disappears. |
06:41 | This shows that there is nothing really wrong with our code but what was wrong in first place, was that this data variable had not been fulfilled. |
06:51 | It's the same as saying "data equals absolutely nothing". |
06:58 | Here let me say "echo variable alex" and this is line 5. |
07:05 | Lets refresh. Undefined variable alex, Undefined index name. |
07:11 | So what we are doing is - okay, let me start from the beginning. |
07:19 | This is unfulfilled if the name has not been specified in the header. |
07:23 | Therefore "data equals nothing" and so we get the error "Undefined index", just like we get "Undefined variable" if we echo a variable that hasn't been set. |
07:35 | So as soon as we put some data in here, this error goes. |
07:39 | Lets refresh . |
07:41 | If you want to get rid of this initial error all you need to do is put a "@ (at)" symbol in between or at the start of this line. |
07:50 | When we refresh, we get nothing because no error has been set. |
07:55 | No get variable has been set. And as soon as we say "name equals alex" our name is echoed out just like the code here specifies. |
08:04 | So even though you are using this "if data exists", technically this still doesn’t exist, if nothing has been put here. So look out for them. |
08:14 | That's all for now. In the last part, I will go through the next two common errors quickly. See you there. |
08:20 | This is Evan Varkey dubbing for the Spoken Tutorial project.
Thanks for watching . |