William Rosener: Welcome back. In this video, we learned how to create a great calculator using PHP. It's a quick look here, what will be created.
William Rosener: I have a look at our header tag at the top will insert your name, but then go ahead and have a couple text boxes for the user can enter data.
William Rosener: Example, a Sicilian or an ad. And how about an 86 on exam to when I hit complete answer. It's going to do two or three things here. It's going to display the average
William Rosener: For the not the soon as passing or failing and they're great. And again, if you take a look up here, you can see that one I
William Rosener: Press that it's going to the server and it's reloading this page. Well, now that we know we want to do. Let's get started here.
William Rosener: So the very first step you want to do is get some really basic editor, such as a notepad or Word Pad notepad plus plus them. So at the very top. What I'm going to typically always do is start off with my PHP right away.
William Rosener: And reason for doing that is if you start putting a few spaces here and you're dealing with images and it's kind of assume that it's an HTML document as opposed to
William Rosener: An image. And so we're trying to have the user downloaded jpg or PNG image there. OK, now I'm going to come down here. We're going to go ahead and start our HTML with this one a little bit more
William Rosener: Each film XML. Correct. And then at the very end here. I'll go ahead and close my HTML. So stands for hyper hyper text Markup Language up here, we may have a head tag.
William Rosener: And we'll go ahead and close the head tag and typically within the head tag, you'll probably find a time on Sunday good put a title in here.
William Rosener: PHP grade.
Calculator.
William Rosener: And make sure you close the title.
William Rosener: Here. Typically there's going to be a body tag.
William Rosener: Close the tag as well.
William Rosener: Just let you know UK would probably wouldn't work perfect whether or not you had all of this information here. It's just kind of
William Rosener: How it's going to help definitely with search engine optimization. If you've got a title that we could go on. So forth knows what this particular document is all about.
William Rosener: OK, so now let's go ahead and let's come up here, let's take, let's start off with a little form down at the bottom.
William Rosener: Well actually the very perceptive wanted to do with some of the header to tag. And I'm going to type of PHP grade calculator.
William Rosener: Then close the heavy to tag.
William Rosener: And then go ahead and put your name.
William Rosener: And again, open and close my paragraph.
William Rosener: I tell you what, if I go ahead and save this and then we'll come along and uploaded and take a look at it in a browser to save it on me come up here to file and we go to save as
William Rosener: And I'm going to hit so all files are momentarily, we were just looking at assignment to PHP completed. But I want to do.
William Rosener: Is
William Rosener: Remove the component
William Rosener: And create our own here. So go to File, Save As. The three things here. Make sure you know where you're saving it out. I'm sitting on the desktop and a porter called a temp.
William Rosener: I'm going to give it a name assignment to dash PHP and make sure it ends with extension PHP and make sure it is a text document and then this point we go ahead and press say at this point, I'm going to go ahead before I can view it. I need to upload it to a server, you hit refresh here.
William Rosener: And this is one we just got done looking at, I'm not going to highlight this one and I'm going to upload it to the server.
William Rosener: Now I can go ahead and take a look at it. And so we go ahead and simply delete some of this information here.
William Rosener: And this was the one we just got done looking at, and this is the one I just created some impressive assignment to PSP and so forth there and nothing too exciting so far.
William Rosener: OK, now go ahead and actually start working on some the code here at two. I'm just gonna grab all this code here make the video little bit shorter there for you.
William Rosener: And explain what all this code is
That
William Rosener: Okay, so take a look here. Tell you what, maybe I'll even done to leave this here momentarily.
William Rosener: Okay, so just like we did in
William Rosener: JavaScript, what's going to happen here is I'm going to have. Well, first of all, I'm going to start a form
William Rosener: It's going to use the method post, it's going to be posting the information and what it's going to do is put this on its own line here.
William Rosener: You're going to see it's going to recursive Lee and effect call itself. So every time I press on the calculated answer button, it's going to call Summit, which is going to call this form again. So it's going to just keep calling itself over and over every time I press the submit button.
William Rosener: Okay, take a look here. We've got a exam one syntax. I've got an input type people text. I'll give it a name. This is the name that will be using with them.
William Rosener: The PHP script at the very top. I've got a submit button and I've got
William Rosener: Some averages and right now if I ran this would probably give me an error because it doesn't know what this this information is let's come up here to the top Lissa go ahead and create some information here as variables to fill that in.
William Rosener: So I'm just gonna go ahead and create a variable here called exam one. I'm just going to sign up your 00
William Rosener: Equals zero some values here and now the other ones here average I could solve this sign at the no string.
William Rosener: You know, repeat the same thing for
William Rosener: Grade. Actually, it was called status.
William Rosener: Here to believe it's called great
Okay.
William Rosener: So now we're going to actually. So what's going to happen as soon as this first time to say is loaded. I'm gonna have some default values.
William Rosener: After that there will be some values entered in here which will be
William Rosener: Calling when we call this form Akin will actually go back to us. So the first time through. I've got some values at the top. So average status and grade.
William Rosener: Average Sasson grade are just going to this is going to do, it's going to start a miniature little PHP application. This is going to start the PHP. This is going to close it.
William Rosener: The actual statement simply going to display what's in the value of the variable average. Well, there's nothing now. Okay, let's go ahead and save this.
William Rosener: And we'll take a look at
William Rosener: Look at a re uploaded can just refresh them. So the, the highlight assignment to hit uploaded.
William Rosener: I can now take a look at what's being displayed, though.
William Rosener: Okay, at this point, when I want to start working on and read some data here so that when I hit the calculate the answer we can display some important information here.
William Rosener: But let me go ahead and grab some code right here. And again, I'm not a chance to chance. So maybe you could ever possibly started off.
William Rosener: You seen what you've already built that you're going to find this kid is very common there, get on the web and just copy and paste that there
William Rosener: And then effect. What this is going to do the trim function is going to remove any extra characters at the beginning, white spaces at the beginning and then have the data.
William Rosener: Stroke slashes and HTML. These are more for security purposes to make sure people have not entered any malicious data that would affect your server there.
William Rosener: OK, now go ahead and I'm going to grab some more code here.
William Rosener: Maybe I could stop it right here.
William Rosener: Let me make sure I close this will be adding some more code right here, what's going to happen is, so I'm going to do a post. So when I press on the submit button.
William Rosener: It's going to post, it's going to call itself. It's going to post this information once I'm going to post information and an exam one and exam. Number two.
William Rosener: So it's going to come up here and post it appear at the very top of pets. The default value sounds are just the first time this particular form is called
William Rosener: Now what's going to happen as I'm going to take the information. Is it not empty. Well, most likely after the user is going to probably hit some data types of data in here.
William Rosener: And now they calculate answer. It's not empty.
William Rosener: So it's going to happen is, is it not empty. If it's not, I'm going to take what's been posted from exam. Number one, I'm going to test the input.
William Rosener: To make sure that the user has entered enough funky data and definitely as, for example, the trim, but that would do is, what if user put some spaces there. It's going to go ahead and turn that data for us. So I'm going to go ahead and have an effect. Make sure exam one and exam to
William Rosener: So legitimate data. OK, the next. Let me describe a couple more lines here.
William Rosener: And paste that this is going to do is it's going to take information in the exam one and exam. Number two.
William Rosener: And just like with JavaScript, I need to make sure I got this parentheses because now I've added like this it would take an
William Rosener: Exam to priority and divisions going to have priority or addition. It's going to divide that and then had which will not give you the correct results. So make sure you get your apprentices here.
William Rosener: This is going to take exam one exam two divided by two and put the out displayed an average. This is going to around average to do two decimal points. At this point, we could actually check it out.
William Rosener: And at this point, we have now computed average. So what's going to happen is like it down here. It's going to echo whatever value is an average there.
William Rosener: So let me say this.
William Rosener: Go ahead and upload this again.
William Rosener: Let's take a look at it. I'm going to refresh.
William Rosener: Lady, and I'm going to check the answer. So I've got 80 and 90 check answer.
William Rosener: Okay, now you're probably gone well gosh this year, two values disappeared or can we do about that.
William Rosener: Well, that's why I deleted this momentarily. What we want to do is simply grab any one of these here and grab this information right here, copy it and I'm going to paste it here and I'm going to put exam one here.
Sure.
William Rosener: I got the camp one on one.
William Rosener: And I'm going to repeat that exact same thing.
William Rosener: copy it and paste it right here and put in exam. Number two. So what's going to happen is when I call this function again when I when I press on the submit button and I call itself.
William Rosener: We're going to now populate this to text boxes with the values that were already there, as opposed to affect possibly using some default values here. So now let's go ahead and save this.
William Rosener: I'm gonna go ahead and upload
William Rosener: When we come back,
William Rosener: I'm going to refresh.
William Rosener: Understand that yes, I can say that I think it's already working here. I'm gonna put 90 going to put some 94 I'm gonna hit calculate answer.
William Rosener: And I can see you can see the little delay there because it's going to the server. And I think my server those there's calm is actually in Arizona. So it's going out to Arizona at GoDaddy and coming back. So look right up here and
William Rosener: Just really just really quickly, but also notice, we do have the time of your PHP okay great calculator. So right there. That's how quick it is. But now, notice that these two values are seeing here. So take a look here. That was the title right up here. That was talking about.
William Rosener: Okay, let's so I'm just going to go ahead and Gramps Morgan here.
William Rosener: And now I'm gonna do is I'm gonna take a look is average greater than or equal to seven day
William Rosener: So on the set the value of status to passing else I'm gonna set the value of status to failing and then might come then what happens is up computed that information.
William Rosener: And now, and I'm displaying my horn. It's going to echo so restart a little PHP close the PHP. I'm an echo whatever is in my variable status. Okay, let's check this out.
William Rosener: And I'll go ahead and upload that
William Rosener: Go ahead and hit refresh.
William Rosener: And to be honest, a lot of times I had to control F5 to force a reload and sure enough, I can see passing already but
William Rosener: To just back up a few times.
William Rosener: Which you prefer press right here. This is why would initially up here.
William Rosener: I could hit 88 and 90 to calculate answer 89 and I can now say I'm getting the past
William Rosener: Okay, getting close to finishing here. We now need to
William Rosener: So this little curly bracket here that is closing this. So if I call this. So the first time, watch this again one more time. The first time I call this, it's got no values.
William Rosener: Game. When I press on the calculator answer now I've got some values, they're going to be posted here and I'm gonna go ahead and shoot. Okay, let's go ahead and I grabbed some code here.
William Rosener: Copy it
William Rosener: And, oops.
William Rosener: And paste
William Rosener: Now take a look. I'ma go is average greater than 90 on the set my verbal grade equal to a house. If it's greater than equal at B, C, D, all the way down to ask
William Rosener: Somebody go ahead and assign a variable greatest gonna have a value. So I'm going to come down here when I get to this part I'm going to start a little PHP script. I'm going to close it on the echo or an effect display whatever information is in grants. Let me go ahead and say that
William Rosener: I'm gonna hit some table. I even hit the back button looks like a upload this
William Rosener: Press on assignment to
William Rosener: Enter in some scores 7019 that I can play the answer it, everything's working perfectly. I'm getting at, and passing in a, be it just to take a look there I'll probably do. Like, I may give you the code here in a graphic format to just sit there and just keep looking at it.
William Rosener: If you're missing a lot of this is a double equal sign. If you get to see equal sign, make sure you get a double square bracket one little thing. And it's also case sensitive one little mistake there. And unfortunately, others good chance, nothing would work them.
William Rosener: Even if I was to accidentally leave off the question mark up here or the angle bracket, except for them so this starts a PHP script.
William Rosener: This is going to close it with an even down in here, we started
William Rosener: And we closed several other PHP scripts as well. Finally, given us this final product right here, watch the next video. Thank you.