William Rosener: This is Dr. Bill, welcome back. In this video, you'll learn how to create a calculator using PHP. Let's just take a quick look at what you want to create and we'll get started on it.
William Rosener: So first of all, I'm having to be able to tag this as PHP calculator or insert your name will have a couple text boxes where people can enter the user can enter data and then calculate answer. So they'll come along and and her and on some values.
William Rosener: And then hit that complete answer it will have those two up and display the answer, but the only difference here that you've probably noticed is if I
William Rosener: Click look up here, what I had to calculate the answer really quickly. It's going to the server to execute this code as opposed to JavaScript, which been executed on the client term.
William Rosener: Okay, well, the very first step, you're going to want to do is open up some very basic editor. Now before I go, I'm just going to every now and then hit the refresh here.
William Rosener: Just some I am FTP connection does not timeout. So the river secular lose you some basic editor, as I mentioned in the JavaScript one
William Rosener: Avoid an editor, such as word which is a new special characters, and even the smartphones, which are just not gonna work in PHP. They're so good. Let's get some really basic editor, like Notepad or Word Pad notepad plus plus to execute your code.
William Rosener: Okay. Very first up one day, was that a little PHP code at the top and a PHP is always going to start with angle bracket, question mark, PHP,
William Rosener: Then to a terminated or simply put a question mark and enable brackets. Okay. And make sure I said at the very top of your code there this kind of discreet a few variables on the Create one called. Number one, you know, I go with the default value zero. Repeat this with a number
William Rosener: Two. It was zero.
William Rosener: And English. Just go ahead. I know when we come along and change in this with that quite a bit of work here to do is just go ahead and put the value of 15 for results so far.
William Rosener: Started some PHP code, close it and all I've done is I've created three variables of the sign number one suburb and PHP and put $1 sign
William Rosener: In front of it to create a variable. So I've got no more than two and resolve three variables. We're not going to come on down here and start our warm it just maybe save a little time, I'm going to go ahead and just copy and paste some code here.
William Rosener: Right here. This is my
William Rosener: First of all, before I even get to them into a type in or heavy to tag reply, type in PHP calculator.
William Rosener: workflows are heading to tag and then go ahead and type in your name.
William Rosener: Paragraph right there.
William Rosener: And delete this here momentarily.
William Rosener: Okay, so that's all I've got. So far this I go ahead and save this and we come up here to file when they go to say that you can save this for whatever you want on the same one on the desktop is the protocol temp, you may want to save it on a jump drive
William Rosener: Flash drive of your hard drive, maybe even though the harddrive if you're working on campus there. So if I take a look here at all files here.
William Rosener: Here's what we discussed on looking at Assignment one PHP completed in order to make sure I say the sense of text document.
William Rosener: So I'm going to go ahead and delete the completed and put PHP. So three steps here important steps to make sure you know where you're saving it. I'm sending it on a desktop and a poor called a temp.
William Rosener: Make sure it ends with the extension PHP another it looks a little redundant, but then
William Rosener: About Assignment one dash JavaScript. And this is the son of one dash PHP with the extension PHP and it's a text document. Make sure you got all three things there. You know, you're saving it file name into a PHP and that and then press say
William Rosener: Okay, this point in order to view this we're going to have to upload it to a server, and then just come along and hit view and hit refresh. And now I can see here is right here at the top here it is on the simply highlight my file and a little bit uploading this to a
William Rosener: Well, I've got a if you're working on my directory that vs students and then your last name here up an instructor and I've got this in a folder called Assignment one
William Rosener: So simply right click and choose upload and there it is. Let's go ahead and take a look at that in the browser will come back here.
William Rosener: I'm gonna hit the refresh button and here it is. Assignment one dash PHP dot PHP and that's all we've got so far. Okay, now we got some more work to do in the best not working. Make sure you close, you get your PHP your closing that header to accept.
William Rosener: Okay, this point, I'm going to go ahead and grab some information. So save a little type in here and a little time and make sure you type that exactly and showed him a break this lineup here.
William Rosener: So we're going to start a form. And before I forget, let me go ahead and close the form, it's gonna take a little while to type that we're going to do a post are going to be calling this particular script over and over again.
William Rosener: The action is notice I'm going to start another PHP script here. It's going to start it, just like I did appear
William Rosener: And then I'm going to put a question mark angle bracket that's going to stop it if you wanted to, you could put a space here just so you can kind of. So we've got our method post our action started with a double quote. And then, and in here really good enough back that up to
William Rosener: Okay. Now, just like we did earlier, we're going to
William Rosener: Type in number one.
William Rosener: Good.
William Rosener: Job script. It was tax.
William Rosener: Number one.
William Rosener: And I'll leave the value up here momentarily.
William Rosener: That we could put a value here.
William Rosener: If we wanted to we can just hard coded and then just like we did with a JavaScript would turn around and
William Rosener: Okay, so I've got number one, I'm going to go ahead and type in number two. I've got input type equals tax, I need to give this a number so that I can access it in my PHP code. And I'm going to give it a default value of the team.
William Rosener: Okay, what's going to happen with my upper right hand corner. Yes.
William Rosener: It's a nice spaces here. Now I'm going to put input type equals submit here's what's going to appear on the screen. Calculate answer you can type anything you want here when I press on this, it's going to
William Rosener: Affect call this form which going to recursive we call itself. In this case, not much is going to happen because I've just got some variables declarative.
William Rosener: Okay, follow the last one is I'm going to go ahead and grab this line right here we come along and paste it and how does that answer. And they were just like I did earlier on the call this one result.
William Rosener: And here.
William Rosener: I'll tell you what. Now we're going to actually grab a little more code because we're just going to first of all written manually take this information and placed in a minute. Notice, come back here and refresh and not sure how long this
William Rosener: is active.
William Rosener: Okay, so now what I want to do is I want to grab that 15 I know what the 15 but we're just going to go ahead and manually, please send in there. And that's going to be angle brackets, question mark, start the PHP, there's an echo statement.
William Rosener: Dollar sign resolved.
William Rosener: So like on and I'm going to terminate.
William Rosener: My PHP and if you want. Maybe I'll put this on another line here.
William Rosener: Okay, so what's going to happen is, I've got an effect really almost I've got three PHP scripts, kind of going on right here. This one right up here at the very top, it's just going to
William Rosener: initialize the variables. I've got another one right in here, which is going to simply call this function over and over
William Rosener: And then down here. What I'm doing is I'm taking the information from result and display in there. So, so go ahead and take a look at this, you come up here to file that save
William Rosener: Come back to my browser. I'm not going to select this file. I'm going to upload it.
William Rosener: Would take a look at my browser. I'm going to hit the refresh. And here's what we got going so far. This will not do anything that we can see and probably should have
William Rosener: Well, I've actually forced I've got the wrong answer here. I've got 15 and five, and I'm getting 15. So why are we getting that 15 that's simply because we're taking this here value.
William Rosener: And I'm placement right into my resolve. Okay. So at this point, maybe we'll go ahead and start doing a little bit more up here. So obviously, probably the first step I'm going to do is set that to
William Rosener: Non and maybe even here. I tell you what we could put change these to the nostril here as well. So I've got number one mission to zero. And I'm to initialize zero. I've got resolved equal to the links for it. So if I was to say that now well
William Rosener: Yeah, this is great because we're actually going to start working on making this kind of implement to I'm gonna go ahead and grab just a little bit more code here.
William Rosener: You probably could find this code on the web.
William Rosener: And this is just going to make sure. So we're going to first of all
William Rosener: We're going to be a writing some code here to that's going to call this test input, but this is going to the trim is going to remove any spaces. Before, and after.
William Rosener: That needs to the strip slashes in the HTML special characters are to make sure that we've got some validate and that someone is not trying to
William Rosener: Add club data into our forum which may try and delete information on the server or except for them. Okay. Maybe I'll go ahead and grab just a little bit more information here.
William Rosener: And I'll paste that
William Rosener: Okay, so just taking a look here.
William Rosener: This was simply declared some variables. This here function, we can now see test input it's going to call this to make sure that no corrupt data has been entered into our form.
William Rosener: And now what I want to do is first of all make sure I close that. So I started the angle bracket. I closed it. I'm now going to go ahead and copy this information.
William Rosener: And paste
William Rosener: Okay, and now what I want to do is change this from number one to learn to
William Rosener: To
William Rosener: Know, to just sit there and keep staring at your code to make sure that you've got every single quote square bracket doubled equal signs, except with them. So what's going to happen is
William Rosener: When the user hits up Submit button, it's going to call itself. It's going to call this form, which in effect cause itself. Now we're going to take a look. Has the user enter that information in number one and until
William Rosener: We get this point we can now go ahead and compute a real results.
William Rosener: And it's simply equal to
William Rosener: Number one plus
William Rosener: Number two, at this point, I definitely want to make sure I do not have. So I've got some default values zero and zero. I had no result.
William Rosener: That way if the first time when they run it. This what's going to happen is this is only going to get called this information right in here. It's only going to get called after they've downloaded the form once and they press the submit button.
William Rosener: Okay, let's go ahead and and take a look at that. I think we're getting really close to finishing this thing. We hit File, Save. I'm gonna come along to my browser. I'm gonna hit select this file uploaded to the server.
William Rosener: I'm gonna come back to my browser. And I'm going to hit refresh.
William Rosener: Look at this is such a plug in some values here or in seven and calculating answer okay what you've not known. Notice if you got everything working right. It has display the answer, but you go, Man, I wish these two values did not disappear because I was to go back
William Rosener: RIGHT AHEAD it you're going to notice that it calls the server. And why did you put those default values in there because I've got nothing here. So now only want to do is rather than just going to grab this code right here to simplify this here a little bit.
William Rosener: Scared right here place in here, rather than echoing about like the practice of the next slide, rather than echo, which is going to display results are going to display them one
William Rosener: And we're gonna have to repeat that exact same thing here from them to
William Rosener: I'm just going to maybe save the time here. I'll grab this kid right here.
William Rosener: I'll copy it.
William Rosener: I'll come over here. I'll paste and maybe I'll just like a decided to put that on its online not change this to them to
William Rosener: Let me check this out. And then I'll come back and explain everything. One last time I come up here to File, Save go to my FTP client. I'm going to upload my new phone.
William Rosener: From to come back to my browser. I'm going to hit refresh.
William Rosener: Okay, I'm now going to put in our value two and three. I'm good kept by the answer, but now notice the two and three are staying there.
William Rosener: Let's just go ahead and take a look at why that is the case. So here's this is my initialization phase.
William Rosener: Of discovery. Now, that is the very first time someone calls this particular script. I'm going to sign of 00 and the double quotes for resolve this code right here is going to simply be notice here, I'm going to test the input.
William Rosener: The information that was posted in number one. So here's, here's one, here's number two. When I press on my Submit button, it's going to post this information. And I just want to make sure that someone has an know previously entered some information like the late Asterix Asterix them.
William Rosener: Or trying to any other type of viruses there and that's this is very common. As soon as you get out there, you're going to find this whole function is what typically most people use. Okay, now take a look
William Rosener: We're taking the information that was posted. I'm gonna take a look. Is it not empty, if it's not empty, I'm going to take what's the number one.
William Rosener: And place it into the variable. Number one, I'm going to take the same thing here might take a look what was posted in number two, is it not empty, if so take it in places the number two.
William Rosener: Number two, number one, plus number two in store in result. Now take a look at the Forum, what's going to happen is this is going to ensure that every time I call it
William Rosener: Pre populates that with the information that was already there. So it's going to the fact that, let's assume I run this phone. I put it to here.
William Rosener: Now what's going to happen is it's going to come up here and it's going to go now on. It's not empty, it's too. So it's going to put a two and two. Number one, and it would come down here and it would go
William Rosener: In fact, this echo statement. It's going to put the value in the morn, the two right into the value of that particular text box there.
William Rosener: Well, let me some one last time. Here's what should happen I shut down. Simply enter a value it. Let's take a look up here and hit calculate answer, it's going to
William Rosener: Call the server, it executes that on the server and displays the answer.
William Rosener: And one huge advantage in time. You don't anything with security etc that you're going to definitely use PHP because, watch this. If I come up here and I go to view page source.
William Rosener: The user does not get to see any information, they don't get to see what's going on behind the scenes is this access in the database was a database name, etc. There
William Rosener: So all this information up here is hidden from the user. All I think to see is the result of the execution of a PHP script there. So a couple things again maybe
William Rosener: If you want to. I've created a folder here called Assignment one have uploaded them into a particular folder, you may want to. So then I would have both the JavaScript and PHP all within one particular on directory
William Rosener: Just going to be some other questions you have. But I think if you keep working on it. You got a lot of those things there. So again, here was a PSP calculator simply two numbers and adding them up and say the answer there. Okay, next video. Thank you.