Bill Rosener: Hello. So, Dr. Bill, welcome back in this video, you'll learn how to create a grid calculator using Php
Bill Rosener: in the previous exercise or assignment. We created a grade calculator using Javascript. And that's going to have run on the client, because now we'll be creating one using Php. Which will execute on the server.
Bill Rosener: So just take a look here, we have a little header tag that, says grade calculator. We'll put your name, have a couple of text boxes, and then, when I press, calculate, answer, 3 things will do. 3 things will happen to compute the average of these 2 exam scores, the status for their passing failing and great. So let me go ahead and press on that. And sure enough, we're getting 87 passing and grading
Bill Rosener: again. One thing here to notice is it's going to execute on the server. So when I take a look up here, when I try this again.
Bill Rosener: calculate grade, I'm not sure if you notice that it went to the server, executed the results, and then the results are submitted back to the browser there.
Bill Rosener: Okay, so let's get started here before jumping in here. Here's assignment 2. And if you press on, here is a screen capture. This is an image of all the code that we'll be looking at.
Bill Rosener: Take a look here, you can. You're going to stop to type it in, though. Here is my desktop. I'm just saving on the desktop in a directory called Temp.
Bill Rosener: and then here is Filezilla. I've got these all ready to go desktop temp, and we can see here is Temp. That's I came right back here. That's where I was placed that in a file called Temp.
Bill Rosener: Okay? So the 1st step here I want to do is open up an editor. I'm using visual studio code, and I'm going to save a little time here, and I'm just going to go ahead and grab some code. We'll kind of stop and paste.
Bill Rosener: Go ahead and grab that code.
Bill Rosener: And I'm gonna come right up here to choose file new text file.
Bill Rosener: I'm just gonna go ahead and
Bill Rosener: put the enter key and paste.
Bill Rosener: and let's just go ahead and stop and take a look at what we just typed in here. We're gonna put a header tag header tags go from h 1 to h 6. I've just gone with header 2 tag.
Bill Rosener: We're gonna close header, tag, go and put your name in there.
Bill Rosener: What do they paragraph break where they're going to start our form?
Bill Rosener: We're gonna close the form. And then this is gonna call itself.
Bill Rosener: So Php, self is going to call itself so every time I press I can enter some new values here.
Bill Rosener: 82, so it can call itself over and over, just not just one time, but multiple times.
Bill Rosener: And then we're going to have our input, we're gonna have exam one exam, 2, and they're going to simply do.
Bill Rosener: It's going to display what is in the variable exam. One same thing here. Display average status and grid. If I ran this right now you would get an error message, so we'll but before this assignment is over I'm going to go ahead and deliberately insert some mistakes here, but let's go ahead and save this
Bill Rosener: we go to save as, and I'm going to call this one assignment 2 dash php.
Bill Rosener: dot, php, so assignment to dash Php, dot, Php. And hit save.
Bill Rosener: So the last one was assignment 2. Dash Javascript. This is assignment 2 dash Php, and then it needs to end with that extension.
Bill Rosener: Okay, at this point, let's go ahead. If I take a look. Here, here's my file.
Bill Rosener: and then here it is my hit refresh.
Bill Rosener: and here it is so I can now upload that, and if I uploaded that and ran it, I would actually probably get a warning message, an error message
Bill Rosener: declared, or those value verbals have no value.
Bill Rosener: So now let me go ahead and press on that, and here is the form. And again, if I came back here, I'm not sure if it's going to have. Sure enough, there is an air log. And well, I'm gonna go ahead and not delete this one because
Bill Rosener: that is simply because I haven't finished working on the code here
Bill Rosener: here. In a minute I'll go ahead and insert an error on purpose.
Bill Rosener: Okay, so I'm gonna go ahead and grab a little code here. Maybe I'll come all the way down here, copy this
Bill Rosener: paste that, and I need to do a couple of things.
Bill Rosener: So this one right here is going to start the Php.
Bill Rosener: this is going to end the Php. Then I had this angle bracket, and that was going to start right here. So the 1st thing I want to do is, I declare, some variables. Exam 1, 2 average status and grade. And now, if I ran it I shouldn't get an error, because they now have.
Bill Rosener: They've got exam. One as 0 exam. 2 as 0. As we saw the average status and grade. There's a null string, but at least they're not undefined.
Bill Rosener: The next thing is that we're going to take a look.
Bill Rosener: We're going to take a look what was posted to exam one. We're going to run it through here. This is some really common code. You'll find out there on the web just to make sure nothing malicious was entered in there like, maybe there's no special characters, etc. There, it's going to simply remove that.
Bill Rosener: Then what I'm going to do is I'm going to take what's in exam. One. Add it to exam 2, divide by 2 store that in average, I'm actually going to round that. So now, average. Well, initially, had
Bill Rosener: the null string. Now, it's actually going to have
Bill Rosener: someone who ran some some values for exam. One exam. 2 will have something display there. So let's go ahead and save this. I'm going to come right up here to save.
Bill Rosener: I'm gonna come here to Filezilla. If I want I could refresh only thing. There is an increase in size and upload.
Bill Rosener: Okay, now let's go ahead and take a look at.
Bill Rosener: I'm gonna go ahead. I can either hit, refresh right here, or if I want to.
Bill Rosener: I can come back to my temp and click on the file and let me put in a value here like 80 and 90, and it calculate great. And sure enough, I'm getting an 85.
Bill Rosener: Okay, let's go ahead and finish this off.
Bill Rosener: I'll grab a few lines of code here.
Bill Rosener: So we did the average.
Bill Rosener: If this line security, it's going to take a look and go. Average is the information in the variable average. Is it greater than 70? Then we're going to set the variable status to passing. And this right down here is going to display or echo what is ever in status.
Bill Rosener: Then we'll go ahead and grab a few more lines of code
Bill Rosener: paste those, and I want to take a look at average, if it's greater than 90, I'm going to set the variable grade to a otherwise, if not, I'll take a look. Is it greater than 80, set it to B, and then finally, this is gonna echo or display what is in grade. So I think at this point we've got everything working. I'm gonna come up here to file save.
Bill Rosener: I'm going to go ahead and upload that and let me hit refresh.
Bill Rosener: And there we go. Okay. So now let me come along here. Come back and hit calculate average. I'm getting passing in the beam.
Bill Rosener: and if I change that to 100,
Bill Rosener: okay, everything is working fine. But let's assume things are not working fine. Let's go ahead and start off. Let's say down here, let's just leave off this equal sign.
Bill Rosener: All I've done is one little equal sign. So I'm gonna go ahead and save this.
Bill Rosener: And you can see that was Line 15.
Bill Rosener: I'm gonna go ahead and upload that.
Bill Rosener: And now we're deliberately inserting some mistakes.
Bill Rosener: I'm gonna come back here, and maybe I'll strip this off.
Bill Rosener: I'll press on this nothing, and you're going. Oh, great! Now, what do I do? Well, if that happens, just simply hit refresh. Here.
Bill Rosener: here is a log file. I'm going to go ahead and download that you can view it.
Bill Rosener: but it's going to cache itself.
Bill Rosener: And then the second and 3rd time you'll keep getting that same file. So I'm gonna download over here.
Bill Rosener: Now I'm going to come along, and I'm going to go ahead and right click on it. And I'm gonna open with, let's just choose notepad.
Bill Rosener: And it's like unexpected double quote, string F online 50. Okay? So now I'm gonna come back and I'm gonna go. Oh, okay.
Bill Rosener: I left off my equal sign. Let's do one more. Let's leave off.
Bill Rosener: How about this
Bill Rosener: bracket right here? And you're going to find that by doing that this here bracket, all this code
Bill Rosener: all the way down to here gets executed. So let me save that I'm gonna upload it.
Bill Rosener: Tell you what a lot of times I will delete these air logs.
Bill Rosener: I'm gonna upload. It got the new version up there.
Bill Rosener: and I'm gonna strip this off
Bill Rosener: press on assignment 2 dot php, again. Nothing. Okay.
Bill Rosener: Now let me hit a refresh.
Bill Rosener: I'm going to download the airlock that's over here.
Bill Rosener: I'm gonna go ahead and right click open it. Notepad.
Bill Rosener: This one is going to be a little trickier because it's going to go unmatched. Curly bracket on line 53.
Bill Rosener: Okay, this is gonna take a little bit more problem solving because you're going
Bill Rosener: initially, you're going to come down here. What's wrong with Line 53. Well, it's got an unmatched and you're going to find that these match. So here we go, this one and this one match, and then this one and this one match. But in this case
Bill Rosener: the curly bracket on Line 16, which was starting. All of this
Bill Rosener: accidentally got left off, and so it kept looking and looking and looking, and final line 53 is going, hey? There was a mismatch on that.
Bill Rosener: Okay, let me go ahead and save this.
Bill Rosener: And then again, typically what I'll do is go ahead and I delete my air fogs.
Bill Rosener: I'll go ahead and upload this.
Bill Rosener: I'll come back to my browser.
Bill Rosener: Press on this. Everything is working perfect but avian and 90 calculate.
Bill Rosener: And sure enough, you there. I noticed a huge delay before that was returned. Anyway, hopefully, in this video, you learn how to create a little calculator using Psp, and I believe in the assignment. I challenge you just a little bit. I've given you the code to work with 2 exams, and you're going to simply add a 3rd exam there, but hopefully,
Bill Rosener: You now know, I should have done that in the 1st video. Hopefully, you learned how to look at your code, and if there is an error, there's going to be an air log produced here on the server. You're going to download that in order to
Bill Rosener: take a look at it. And again, if we take a look, here's the beauty of
Bill Rosener: Php! Here's the here's all the code. But when I come along. And if I come along and go up here and go to view Page source like someone wants to steal our code, they can't, because this is all that they can view is the output. They can't actually view the Php code itself. Even here there was some Ph code that simply said Echo
Bill Rosener: average. But in this case all it's doing is putting the 85. So if you're going to be spending much time working, creating an application definitely accessing databases.
Bill Rosener: or you don't want someone literally, just to take your code and copy and paste it. You'll probably most likely want to be looking at Php, well, hopefully in this video again, you learn how to create a little great calculator. And I'll catch you next. Video. Thanks a lot.