Bill Rosener: This is Dr. Bill Rosener. Welcome back in this video you learned how to create a calculator using Php in the last assignment we created this exact same calculator using Javascript and Javascript is going to run on the client, whereas Php is going to run on the server and let's go ahead and take a look at this, and then we'll be recreating this line by line.
Bill Rosener: so we'll start off a little header to tag. Had one tag. We'll just have Php. Calculator. Insert your name. We have a couple of text boxes where the users can enter numbers. Then I'll hit that calculate answer, and that is going to take these 2 numbers and add them up.
Bill Rosener: and one little thing there before we move on is
Bill Rosener: take a look up here and you'll see a little kind of a dot fly back and forth, and then also maybe notice the delay. So I'm gonna press the calculate the answer.
Bill Rosener: and it's pretty quick. This is actually going to the server computing the results and then return them back to my browser. There.
Bill Rosener: okay.
Bill Rosener: let's go ahead. Now. We know what we're doing. Let's go ahead and get started. So I'm gonna 1st of all, let me just show you. Here is my, I'm gonna be working in a
Bill Rosener: temp directory on my desktop. Here was one we just got done looking at.
Bill Rosener: and then if I take a look at, and I'm going to have a video, too, here, or some text on showing you how to upload your work. And I'm just going to be saving this on my folder my directory, Bill rosen.com, and a folder called Tip, and I can see here is the current one.
Bill Rosener: and let me just
Bill Rosener: walk for whoops. Let me come right back here and let me start off. I'm gonna try and set up your account so you shouldn't even have to worry about this, but notice if I was to delete this dot HD access file.
Bill Rosener: Then if I came back here and
Bill Rosener: tried to do a directory listing, it's going to say 403 forbidden air. And so for that reason I'm going to go ahead and upload this dot HD access file.
Bill Rosener: and I need to rename it.
Bill Rosener: Just remove. It has to be a dot HD access. I'm gonna simply remove that dot txt at the end. And now, if I come along.
Bill Rosener: I can do a directory listing, and I can see all my files there.
Bill Rosener: Okay, so let's move on here. I've now got visual studio opened up and let's get started here. So the very 1st step I'll do is come up here to file new text file, and we'll start off with a little header to tag.
Bill Rosener: We can use header one if you want.
Bill Rosener: The reason I use it, too, is because I don't have to worry about anyone confusing
Bill Rosener: a 1 and an L, and we just put that Php calculator.
Bill Rosener: We'll go ahead and close our header to tag
Bill Rosener: and then go ahead and put your name there
Bill Rosener: and then we'll put a little paragraph break. Just get right in.
Bill Rosener: Okay, we're ready to save this. So I'm gonna go ahead and come right up here to file. I'm gonna choose, save as.
Bill Rosener: And this one needs to end with the extension. Php, so I'm going to call this assignment.
Bill Rosener: one dash psp, dot, psp, so
Bill Rosener: this was kind of the reason I put the dash Php. Because we had 2 assignments, the exact same assignment. One was on Javascript, Js, and then this one is on Php. But this one also has to end with the extension dot Php. And let me hit, save, and then you should see this a little bit bigger here. So I named it assignment one dot dash php, and it has to end with that extension. Dot. Php, there.
Bill Rosener: Okay, well, let's go ahead and we'll be doing this numerous times uploading it. So I'm gonna come over here to my ftp client.
Bill Rosener: I'm gonna go ahead and hit, view, refresh.
Bill Rosener: And well, actually, here it is already. Then I'm simply right. Click on it and upload.
Bill Rosener: And now it's up there on the server. And so now, if I come back
Bill Rosener: and I hit refresh here
Bill Rosener: I can. Here's the file just got done created. I can go ahead and click on that. And sure enough, we've got Php, calculator and my name. Okay, got some work to do here. But let's go ahead. And I get started. So the next step I'm gonna do is start working on the form, and then we'll come back and start working on the Php.
Bill Rosener: yeah, we got some code to put in right here.
Bill Rosener: and what I'm going to do is give you some of the code. So let's go ahead and take a look here at the assignment one.
Bill Rosener: So here is a screen capture that shows all the code. But just to make sure, you guys, I've had students that mess up with these underscores and some of the double quotes and the square brackets. I'm going to get you a little bit of the code here. So there's also this partial code here. And I'm going to go ahead and grab this information right here.
Bill Rosener: copy that.
Bill Rosener: And I'm going to go ahead. And
Bill Rosener: I'm gonna 1st of all. And actually, I need to start my Php.
Bill Rosener: then I'm gonna go ahead and close my Php.
Bill Rosener: and then here's where I'm going to insert that information there. So we're going to be doing this numerous times anytime you want to start
Bill Rosener: a Php.
Bill Rosener: we put angle bracket question. Mark Php, in this case it's just going to be a column itself. This is going to close it. And then this right here is closing.
Bill Rosener: This is 1st the double quotes closing the action. And then this is closing the form.
Bill Rosener: Okay, we're now ready to put a number. I'll put the number one, Colon input. Type equals text
Bill Rosener: name equals. Call this a number one
Bill Rosener: and value equals. And I could start off. I'll put just to put a value in here. Say, 20.
Bill Rosener: But we're gonna come back and change that here in just one second here.
Bill Rosener: actually almost need to start working on the Php to even begin to have that start to make sense here.
Bill Rosener: Okay, but I'll tell you what. Let me go ahead and just save this.
Bill Rosener: I'll go to file, save, and you can see you can just hit control. S. To save that.
Bill Rosener: Then I'll go ahead and come right over here and reload.
Bill Rosener: And always I'm going to choose this. Always use this action. So now in the future, and just simply override.
Bill Rosener: come back here and refresh. And there we go. We've got number one with a value in there.
Bill Rosener: Okay, but what I wanted to do. Well, I'll tell you. Let me just go ahead and get a little bit more information, and then we'll come back and make some changes there.
Bill Rosener: So now let's go ahead, and I simply take that took that line. I'm going to go ahead and copy and paste it.
Bill Rosener: I'm gonna change. Make sure you get both of these. Now, we're gonna have another text area.
Bill Rosener: a text box where users can enter information. And that's going to be Num. 2, and I'll put a different value in here, and if you want, it looks like I had 2 spaces there, and there's no no magic. You can put as many spaces. I typically put at least one.
Bill Rosener: Okay, and then we'll go ahead and begin our command button.
Bill Rosener: And then what do I want to appear on the screen? And I'll have a calculate answer.
Bill Rosener: and then we'll go ahead and actually have another text box where we'll display the result.
Bill Rosener: I'm just gonna go ahead and copy this. I'll save just a little bit of time here, paste it, and then here I'll put
Bill Rosener: oops total, and that's going to be input, type, text
Bill Rosener: name equals. I'll just call this result and then value.
Bill Rosener: I'll put nothing in there.
Bill Rosener: And again, we need to. We're gonna have to come back and modify these value statements on all 3 of these. And before we're finished here, let's just go ahead and take a look at what we've got here so far. So I'm gonna come along and come to file. I'm gonna choose, save
Bill Rosener: go ahead and right click, upload
Bill Rosener: and back to my browser and refresh. And so now I've kind of got everything in place here.
Bill Rosener: What's gonna happen is actually, when I press calculate. Can you see it's actually calling it on the server? But nothing is happening yet, because we really haven't worked on the Php code itself yet.
Bill Rosener: Okay. So anyway, our forms looking good. Now, what I'm gonna do is I come up here more towards the top.
Bill Rosener: and I think I'll just put this way at the very top there.
Bill Rosener: and I'm just go ahead and angle brack
Bill Rosener: angle, bracket question mark. Php, that's gonna start.
Bill Rosener: And then maybe before I forget I'm gonna go ahead and close my Php.
Bill Rosener: so the very top is, go and create some variables. We'll create one called result. We'll set it to well, we could set it to 0.
Bill Rosener: And then I'm gonna create another one for number one equals.
Bill Rosener: Tell you what let's put. We're gonna hard code these, and then
Bill Rosener: we'll go ahead and actually make this thing work. So them 2 equals
Bill Rosener: great. Just give it any value you want.
Bill Rosener: And now it's really good idea. Actually, let me go ahead and copy a little bit more coast here.
Bill Rosener: I'll tell you what what we could do is simply go dollar sign result equals
Bill Rosener: dollar sign number one, plus
Bill Rosener: dollar sign number 2. So it's gonna 90. It's gonna ignore the 20 and the 10. When we actually press on this. Make sure you got your semicolon there. And so now, what I'm gonna do is I'm gonna come down here on the value. And here we're gonna go ahead and put in. We're gonna start a Php.
Bill Rosener: so it's going to be angle bracket
Bill Rosener: question mark Php, and maybe before you forget, let's go ahead and close that.
Bill Rosener: And what I'm going to do here is Echo, what's in the variable result?
Bill Rosener: Okay.
Bill Rosener: so I've got an echo statement that's going to simply display what is in result and what is in result is 10 plus 3. So it should give me 13.
Bill Rosener: Okay, let's go ahead and save this.
Bill Rosener: and we still got lots of work to do here. I'm kind of slowly building this thing. I'm gonna go ahead and upload that
Bill Rosener: I'm gonna go ahead and hit refresh.
Bill Rosener: And actually I can see as soon as I hit.
Bill Rosener: Calculate answer.
Bill Rosener: It's displaying 13 there. Okay.
Bill Rosener: but we're not actually really. And again. I'm kind of building this step by step, is we're not actually even looking at these values initially. So initially, all I'm doing is I've declared some variables.
Bill Rosener: and I'm going to simply add them up and put them in there. Now let's begin to grab the value out of these 2 text boxes, and so we can add them up.
Bill Rosener: And again, like earlier, like I mentioned earlier, let's go ahead and
Bill Rosener: let's grab some code here. I'm just going to grab all this code right here. Now, the 1st one is just to kind of test the input, make sure. No one has inserted in a.
Bill Rosener: you know, misleading data
Bill Rosener: or corrupt data, and then we'll go ahead and begin with our process and the information. So I'm gonna take that information.
Bill Rosener: I'm gonna come along and paste this. And I'm gonna put that I'm gonna paste that right up here.
Bill Rosener: Okay? And so now, what we're going to do is we are going to see is if number one has been posted, then we're going to. 1st of all, we're going to process it through the test, input making sure no devious information has been entered
Bill Rosener: into our text boxes. And now
Bill Rosener: I'll tell you what. Now let's just go ahead and let's grab
Bill Rosener: that information. So again, I kind of give you that just because I've had students in the past. So only for one equal sign that needs that to leave off a parentheses and nothing works. So I'm gonna go ahead and copy this information.
Bill Rosener: And I'm going to paste it.
Bill Rosener: And I'm going to simply change this to 2
Bill Rosener: and change that to 2. And now make sure you get this closing Curly. Actually.
Bill Rosener: I'm gonna put that down here, closed in curly bracket. I should have. Actually.
Bill Rosener: I must have had that in there earlier.
Bill Rosener: Okay, so let's take a look here, what's happening now is, well, we're still using tell you what, we can go ahead. And now we're no longer using these values. So if you want, I'm gonna go ahead and change this to 0, 0. So we're just kind of initializing them to some value.
Bill Rosener: but when I call it, it's going to kind of keep calling itself. When I press on the calculate answer, it's going to hit submit, which is going to call Php self call itself. And now it's going to be taking these values which we'll be removing here in just a second. So let's go ahead and save this.
Bill Rosener: I'm gonna go ahead and come right over here and upload
Bill Rosener: and let's go ahead and come back here, and I was just. You can hit the refresh here.
Bill Rosener: or you could even just come along and strip this all off
Bill Rosener: and hit assignment one dot Php.
Bill Rosener: And now let me hit, calculate, answer.
Bill Rosener: and let me take a look here. Looks like I've kind of messed up already on on the code.
Bill Rosener: So oh, here we go. This one needs to say, number 2,
Bill Rosener: num, 2, num, 2, num, 2. Let me go ahead and save this.
Bill Rosener: Come along and upload that.
Bill Rosener: And let's see if this one happens to be working. Now again, you can refresh, or
Bill Rosener: you could delete that all like I did a second ago. Press on it again. And now let me hit that calculate answer, and I get 30.
Bill Rosener: Okay, but watch this. It's like,
Bill Rosener: I put 15 in there.
Bill Rosener: It's going to get 35. And now when I press it again.
Bill Rosener: and do you see how these values? I'm gonna change this to 5 and say, 4. Okay. The 1st time I get 9.
Bill Rosener: Well, let me. Can you see what happened there? It's adding it up.
Bill Rosener: But my values are being deleted. So whatever values I put in here.
Bill Rosener: They were there initially.
Bill Rosener: but then, when I execute it, they get overwritten. Okay, to fix that, all we need to do is come back here, and rather than actually, I shouldn't even displaying that 20 or the 10 is we're going to simply echo, display what is in that variable, and what it could do is just grab this right here, this code here.
Bill Rosener: copy it, and I'll paste it right here.
Bill Rosener: and then I'm going to change this result to number one.
Bill Rosener: and we don't. I can maybe delete a extra space there
Bill Rosener: and then maybe I'll go ahead and delete this information.
Bill Rosener: copy it and paste it here, and I'll change that one.
Bill Rosener: Go to. Okay. So now, the 1st time through
Bill Rosener: it's going to initialize the values to 0 and 0.
Bill Rosener: And so they're going to have zeros there.
Bill Rosener: And now, when I press submit button, it's going to be coming up here, it's going to be calling itself. It's going to be finding, extracting information. I'm wanting them to add them, lessen it in result. And it's going to simply echo that out. Let's go ahead and check this out. I'm going to come up here to file, save
Bill Rosener: come back here, hit, refresh, or I mean upload.
Bill Rosener: and we come back to my browser.
Bill Rosener: And this time, actually, I'm gonna start from scratch. Let me go ahead and delete this song.
Bill Rosener: I'm going to press on assignment one dot. Php, see how we're getting the 0 and the 0.
Bill Rosener: Now, I'm gonna put 1020.
Bill Rosener: And now I'm gonna hit put 5.
Bill Rosener: And now when I hit calculate. So I get 25. But notice, these 2 values are now Stan.
Bill Rosener: So I'm gonna put 10 and 4,
Bill Rosener: we get 14. And those 2 values are, Stan, and how come they are? Stan is because we're going to go ahead and
Bill Rosener: we're going to post. We're going to call that this thing is going to call itself.
Bill Rosener: But notice.
Bill Rosener: we are going to extract the value of Num one and Num 2. They're going to be stored in variables. And then we're going to turn right around and display that in the value
Bill Rosener: boot camp.
Bill Rosener: So hopefully in this video,
Bill Rosener: and I didn't even do anything with AI but feel free to use Codem or some other AI, and explore this a little bit more. But hopefully, in this video you learned how to add 2 numbers using Php, and maybe one last thing is, the beauty of Php is, or the main reason is used because someone visiting the web cannot look at your source code. So anyway, here was the source code right up here. All I mean, it really wasn't all that much.
Bill Rosener: So this was kind of like the Php code
Bill Rosener: and someone visiting the website. They don't get to see any of that. Let's go ahead and take a look at that. So let me put a different number in here.
Bill Rosener: Okay, but now, if I come over here and I go to view Page Source.
Bill Rosener: you don't see that all that you get to see is the results that were produced by the P. Executing the Php. Code, and I can see my 10 and my 5 here. But I don't get to see the code itself. So if I'm going to spend hours and hours developing an application.
Bill Rosener: I'm not going to use Javascript where someone can literally just view my code and copy and paste. And also anytime you're working on a server, maybe with the database. Then also, you're gonna be wanting to use. Php, but anyway, I think that's going to kind of wrap up this video hopefully in this video again, you learned how to use Php to simply add 2 numbers, and again take a look at that every time I press on right up here, and I press calculate, answer. It's going to the server calculating the answer and then returning that back to the browser. Okay, I'll catch you next. Video. Thanks a lot back.