Placeholder Image

Subtitles section Play video

  • creating these classes requires equipment and service.

  • Is that cost money?

  • If you appreciate this education, please think about going to Eli the computer guy dot com and offering a one time or monthly recurring donation.

  • Welcome back.

  • As you know, I am Eli the computer guy.

  • And in today's class, I'm going to show you how to use an HTML form in order to update records.

  • And you're my sequel table using P A.

  • P.

  • So this is a pretty nifty toe.

  • Nifty Neto class today, Essentially, what we're going to be doing is we're going to be using to p a P Scripts.

  • The first PHP script is going to dynamically arrange an HTML form for you.

  • So basically, you're going to call this PHP script.

  • You were going to say What student i d.

  • You're looking forwards or want to create a student?

  • I d variable will just plug in a number for that student I d.

  • You know, one through.

  • I think we have, like, 19 students at this point in the table that we have.

  • What will happen is the pH be script we'll go through.

  • It will find the record associated with that student i d.

  • And then what will happen is it'll write out an HTML form and then in the default spaces.

  • It will then add whatever is currently in the records.

  • So let's say if we did Ah, student I d number five student i d.

  • The number five might be student Timmy who is a boy who was six years old.

  • So basically, when the form has created, not only will you see the name and the age and the gender, but it will already be defaulted to whatever the record currently is.

  • So, Timmy boy, six years old, then what will happen is if you want to update that information like you would with an HTML form, basically, you can simply just type in something new or select something different in the option box.

  • You hit the submit when you hit the submit this now dynamically created form, we'll submit the information that you you have plugged in to an update PHP script which will then update the record that you were looking at based with the information that you have just inserted.

  • So today we're going to be using to PHP scripts.

  • One PHP script is essentially just going to be a standard update script like we've used previously.

  • The first script is going be a PHP script, but basically what's going to do is is going to dynamically build on HTML Web page for you and pre populate that form with what is already in the record.

  • So there are a couple of warning warnings today.

  • The first important warning warning today is to be careful of your Web browser cashing the form information.

  • So when I was going and I was doing this lab and I was playing around with different settings, one of the issues that I ran into is that basically the Web browser, Firefox would cash some of the fields where I had entered information.

  • And then when I hit refresh instead of pulling in the new information like it was supposed to go, it just used the cached information that it already had cashed.

  • So one thing if you're playing around with the scripts and you're getting like, weird output from the form, one of things you may want to do is instead of a refreshing the form refreshing the script actually close that tab a re open that that script PHP script that I'm going to showing you in a different tab, and then that should pull in all new information.

  • So the first thing to be doing the warning warning about today is Do be careful of your Web browser cashing a data that may give you some some weird output.

  • If if you're not, if you don't know that that may happen.

  • The other warning warning that I will give you is my code may look gnarly today.

  • Look, I'll be honest with you.

  • I'm showing you folks how all this stuff kind of works.

  • The code that I actually write can look a little messy.

  • Might not always be up to the standards of those professionals out there s o do Just keep us in mind when I'm going through the code.

  • When I am showing you things again, I am trying.

  • Thio teach you in a way that you understand what is going on with the hope that later once you do grasp that concept, you'll learn howto be able, do proper syntax and write all of it all pretty for the professionals.

  • Uh, but just keep that in mind today.

  • Something code that I'm I'm writing for you does look a little bit gnarly.

  • The reason that I'm writing it in the way that I am is because I think it is easier to understand.

  • But again, in the real world, let's just say some coders my ass and his secrets.

  • So anyways, with that, let's go over the computer and I will show you how this code works.

  • Day.

  • So here we are, at my lab environment again, I'm using to bunt to desktop 18.4 Lt s this is running within a virtual machine on virtual box.

  • And I'm using a Mac book pro.

  • In order to create the lamp stack on this demonstration machine, I use something called tasks L t A s K S E L.

  • It's a tool that allows you to install the entire lamp stack packing my sequel PHP all default configurations.

  • I have not modified PHP.

  • Donna and I have not modified V hosts or anything like that.

  • The only modification it all is I didn't put a PHP folder in the root directory of Apache again, so I had some place to dump the PHP scripts beyond that in order to actually write the scripts that I'm showing you today.

  • I am using G edit.

  • So this is the equivalent of no pat or text edit.

  • And either the Windows or the Mac world, just basically a crappy little text editor.

  • Because when I'm writing relatively small scripts, I do like showing you folks that you could just use a crappy text editor in order to do that.

  • The version that we need to do is we need to go over and take a look at our my sequel database and understand How are my secret database works before we actually start getting into the scripts today to go down to the whole show applications they're up to go terminal, they're going to enter at the command.

  • Proud.

  • Of course you do.

  • My sequel space hyphen you off whatever your user name is, Bob has always a space Siphon Peed asked for the password.

  • That sort of 123456 and we're now in my sequel from here We're going to go showed at a basis basis because we always want to make sure we understand the environment we're dealing with, especially before do modifications to our databases or tables.

  • This shows us.

  • The databases that we have in the server of the database that we care about today and that we've been using is class D.

  • B to the Duke use Class B semi colon.

  • Of course, once we get into the database, we will the new show tables.

  • So this will show us the tables in this particular database on with these tables with this database, we do have multiple tables because we've been using this for all the projects up until now, the table that we care about today is the student stable.

  • Now, I will highly recommend that you create a backup of your students table, especially when you're playing around.

  • Since we're doing an update today, right?

  • If you screw up an update in a script, you can you can really Ho's your table really quick.

  • So I would highly recommend you take the three and 1/2 seconds required in order to create a backup your students table so that if you do something stupid, you could recover relatively quickly.

  • From that we're going to do describe the E S C students semi colon.

  • Yes.

  • So we can see what this table looks like.

  • This table has four field a student i d.

  • A name and age, a tender and a uniform student.

  • I D Field is an important field.

  • It's an integer, and it's an auto increment.

  • So the student I d.

  • Is going to be important today when we were up.

  • Basically, when we're searching and we're updating records because within a my sequel database table, you need some feel that is absolutely unique for all records.

  • That name may be the same.

  • The egg is maybe the same.

  • That gender may be the same, but you need something that's absolutely unique.

  • What happens when you have to think about is what happens if you have two records where the name is Bob.

  • The ages 11 and the gender is boy right.

  • That's to quote unquote identical records, which is just gonna cause a mess of problems because the computer is gonna know which record you actually want to deal with.

  • So by having one absolutely unique a field that means that that all records will have a least one part that's absolutely unique.

  • So for here, that's a student I d.

  • So you may have Bob 11 boy Bob 11 boy, but it will be student i d.

  • One for Bob 11.

  • Boy and student I d two for Bob.

  • 11 boys at least something There will be, um get name is text Ages into your gender is text in uniform.

  • His text thing.

  • If we do select Oh, all from students, we can see what records we do have in this particular table.

  • Let me increase the size of this window a little bit and so we can get a C student.

  • I d name, age, gender and uniforms.

  • Student I d.

  • One is Bobby a 12 gender boy.

  • That person has a blazer student idea.

  • Four Freddie 14 boy, also a blazer.

  • You so wanted so forth, you know, student idea 15.

  • Her name is Sue.

  • She is 23 years old, She's a girl and she does not have a uniform.

  • So this is what the data on the table looks like.

  • This is what we're going to be interacting eso from that lets go and actually take a look at the web browser so before.

  • Oh, before we actually start doing the project, I just want to show you what the results the product project should look like.

  • So you type in 1 27 0.0 Not one.

  • That is the loop back address.

  • Basically, that is the address when you're trying to get to the Web server on the computer itself, we put in PHP because, as I said before, I have a PH.

  • D folder and then we're going to do is we're going to go to the PHP update form dot PHP script.

  • So the dot PHP So at the end here, this is not PHP.

  • So this is going to dynamically, right?

  • An a t m l A form for us.

  • So it's going to write.

  • The eight came out form and based off of the record number, we give the script.

  • It will then pre populate the fields of that HTML form with whatever the information is within the record.

  • S o do realize.

  • Yes, it's yes, it's an HTML form, but you do have to end it with dot PHP in order for the peace be script to work, right.

  • So where dynamically Right?

  • In an HTML form using pH, we're gonna hit enter.

  • And so basically this pops up.

  • So we have a student.

  • I d here.

  • So a student i d here is a five.

  • So I've actually put that in statically within the code.

  • Just make life easier.

  • This person has a uniform of a blazer.

  • Their name is Tim.

  • Their ages 80 and their gender is boy, we go down here, we could take a look.

  • This is my secret.

  • Out of a stable itself.

  • There was student idea five.

  • We have a name of Tim.

  • You have an age of 80.

  • We have a gender of boy on this has a blazer, right s.

  • So maybe maybe it's like we're looking at this and going Oh, crap.

  • Tim, Tim isn't 80.

  • Tim is.

  • Tim is eight.

  • Tim is actually supposed to be eight.

  • And if 10 is a, we shouldn't be calling him.

  • Tim could.

  • That's that's what you call a man.

  • We should be calling him Timmy.

  • Right.

  • So let's make these modifications s o.

  • We do the submit query here.

  • We just get a little Basically, this is just a report just to say that the update has occurred.

  • So records updated student idea five is now Timmy, age eight, boy, which obviously is different than what's here.

  • But if we do a refresh basically gonna select all from students and we hit inner We can see now See that student i d five is Timmy is now eight and is a boy, so that's what we're going to be doing today.

  • We're going to be dynamically creating an HTML form using PHP, pre populating that HTML form with the information that is in the records on.

  • Then we'll be able to modify them so that let's go over and actually take a look at the code Esso per day.

  • We have two scripts.

  • We have a script called PHP update form dot PHP.

  • Basically, this is going to dynamically create that html forem.