Placeholder Image

字幕表 動画を再生する

  • 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 clients, I'm going to show you how to create an HTML form so that you can serve through your records and your my sequel database tables.

  • So before I showed you how to create an HTML form that allows you to insert records into your tables now we're going to use a form so that you can search through those records.

  • Essentially, what we're going to do is we're going to create a form that will allow you to input whatever it is you're looking for that will then pass the information to a PHP script.

  • PHP script will then go.

  • It'll serve through.

  • You're my secret database table, and then you will then a print out of the results that match your query to a basic HTML screen.

  • I will tell you what I'm going to be showing to you today is, uh really is hell.

  • It's gonna be ugly.

  • It's got to be ugly.

  • I would not suggest you, uh, you handing this over to a user.

  • But I do want to show you basically how you're able to use HTML PHP and my sequel to now be able to search through records and then pre able to present a result in a Web browser.

  • So the big concept to keep your eye on today when I'm showing you how to create the HTML form and be able to do the search functionality with PHP is to be looking at the wild car functionality.

  • So normally, when we have been searching through on my sequel database tables, we've been doing, you know, select all from whatever the table is where column name equals something, right when you use equal something.

  • Basically, the only results that are gonna pop up are the results that exactly equal whatever you've plugged in there.

  • So if you type in, let's say Bob on Lee results that hat that are Bob will show up.

  • You won't get Bob as a Bobby as a b o B B Y.

  • You won't get Bobby as a b o b B i e.

  • Right.

  • So that's one of things.

  • When you're thinking about creating a search form, people aren't always sure exactly what they're searching for.

  • So they want to type in.

  • They won't be able to type in a little bit of a snippet and then have any results that match that snippet show up.

  • So again, when you do the normal select all from table name where column name equals, uh, you run into the problem where it will only pop up with the exact match for whatever you've plugged in there.

  • So what we're gonna be using today is wild cards s.

  • We're going to be using the percentage sign while on card.

  • So basically with percentage sign wild card means is anything, any amount and any whatever.

  • Right, s So you see this a lot like with, uh, with asterisks and some coding languages where you can put in asterisks And then again, like anything that matches whatever the middle bit is that will then show up Well, basically, with the percentage signs, you get the same thing.

  • So instead of saying equals so select all from table where you know it's a name equals Bob we're going to do is we're gonna say where name like they're gonna take out the equals, Say, like, and we're gonna We're gonna put the variable But then we're gonna put percent signs on either side.

  • So basically is going to say where um, anything is like we give the variable name.

  • So the variable with any match in front and any match behind and it will print out their results.

  • So with this, when you use a like if I simply put in b o B, then Bob will show up and a Bobby B o B b.

  • Why will show up and b o B b i e will show up, right?

  • So basically anything that has that bob in the middle that will show up One of the examples that will show you is with Jimmy and Timmy.

  • So have Ah, I have some Timmy's and I have a Jimmy right?

  • So I can put in I am and why?

  • And since I had that percent to sign in the beginning, then the results that will pop up is Timmy will pop up and give me will pop up and basically any names with I and why will pop up.

  • So this is one of the values of wild cards, and so is something that you need to be thinking about when you're creating search forms because people will not know exactly what a plug it again.

  • If you think even you're thinking about a name making sure you don't misspell it, making sure you know enough is it to bees or one B?

  • Is it I e.

  • Or is it why things like that?

  • If you could just plug in a little bit of a snippet of whatever word you're looking for, then you can get all the results and then go, Oh yeah, that's the one that I'm looking for.

  • That's the value of wild cards and so wild cards used, like so instead of equal use alike on.

  • Then again, I say we're gonna use a percentage sign the beginning percentage sign of the end, so that will show us.

  • Basically, we give the snippet with any any result that has anything in front of that snippet and any result that has anything behind that snippet that will show up in the results that I'm going to be showing you.

  • There's no real warning warnings for today again, usually when you were dealing with my sequel databases.

  • There's a whole bunch of warnings where you could really, really screw something up.

  • Since we're simply doing a select statement today, there's nothing that you should really be able to destroy.

  • Should should.

  • There's nothing.

  • You should be able to destroy it now with you folks.

  • Who the hell knows what you're going to go?

  • The main thing that I would say for the warning warning today is mainly that you should look at what I'm doing.

  • Look at the demonstrations that I am giving you and then start to play with these these things yourselves again.

  • One of the big problems in the programming world is that people try to do everything paint by numbers.

  • Right.

  • OK, do this and do this and do this and do this.

  • And this gives me a specific thing, right?

  • Well, one of things in the coding world to realize is you're more dealing with things like bricks.

  • I'm basically giving you bricks and then you can build the bricks.

  • You can build whatever you want.

  • Like I show you how to put bricks together.

  • And then you could make a wall or you could make a building or you could make a septic tank right.

  • There's a lot of different things that you could do with bricks.

  • So what I want you to be thinking about today is with the things that I'm showing you to do again.

  • Now that you have the HTML form now, they have appeared to be script.

  • Now they have my secret database and tables start looking at what I'm doing and then start playing around with your own configurations.

  • Create your own tables, create your own, you know, small little projects, see what works.

  • See what doesn't work.

  • Andi think that's one of going to one of the big things that you should take away from today is Don't look at what I'm doing today as an exact model of what you should exactly try to replicate Takeaway.

  • Oh, these are things that I can do and then start playing and seeing what you're able to come up with yourself.

  • So now that we have that, either way, we're gonna go over the computer show.

  • I'm going to show you the demonstrations today.

  • We're actually going to have to demonstrations today.

  • The first is where we're basically going to create a simple search box that will serve through names within the students table that we have been using for previous projects.

  • Us.

  • We have a student's table.

  • The students table has a student name.

  • It has an age, has a gender, has a uniform s o.

  • The first project that we're going to do today is that we're simply going to search through the names and then simply print out the results of that match with whatever name that we have plugged in.

  • The second example that I'm going to show you today is where we're then going to add an option box and tell the search form what column we want to search.

  • So first, the first of the demonstration we're gonna do is all it's gonna do is search through the name.

  • So we're going to hard code the column name, name into the code that we've created and will only serve through the name column.

  • What we're going to be doing for the second project, though, is we're gonna have an option box and that option boxes going to ask.

  • You want to search through the name column?

  • Do you want to search through the age problem.

  • Where do you want to search through the gender call?

  • Right.

  • So I could simply plug in, lets a girl into the search box, then select a gender.

  • And then it was Then it will serve through the gender column.

  • And any gender that matches with girl, it will print that result.

  • Or if I want to do a GE, I will plug in.

  • You know, the eight, let's say 12 into the age call urn to the age where?

  • Into the search box.

  • Then I will select the age column And then any record of that matches 12 for the age that will show up.

  • So those are the two projects that we're going to do it today On With that, let's go over the computer.

  • I can show you how this works.

  • So here we are.

  • My demonstration system.

  • The exact same demonstration system I always use.

  • But if you're new here, I'm using a bunk.

  • You a desktop?

  • 18.4 Lt s again.

  • You should be able to use any who want to desktop.

  • What I'm showing you today will work.

  • I have that running within a virtual machine and virtual box and I have this on my Mac book Pro You bunch of desktop 18.4 I did use something called Task Cell in order to install the entire lamp stack.

  • So packing my sequel and PHP is installed on the system, they are all at their default.

  • I have not configured PHP dot i and I have not modified V hosts.

  • It's all just the standard configuration.

  • The only thing that I've done at all is in the Apache.

  • A root directory.

  • I created a folder called PHP simply to dump all of these PHP example scripts and have them in one place a SW far as the editor that I am using for the code today.

  • I'm simply using G edit.

  • This is just a basic, really crappy editor, the equivalent of text edit on Mac or no pad within Windows again.

  • When I am doing small projects, I like using crappy little text editors because it makes it simple for you folks to realize, Oh, you don't need a fancy I d.

  • You don't need some kind of fancy editor in order to create the scripts that I'm showing you today.

  • So with that, let's go over Aziz always.

  • And take a look at our my sequel database to make sure we know what's going on.

  • There s So you go down to do that a little quick on the things down, the bottom and the surf.

  • You go to terminal that.

  • So basically we had to our terminal right now we're gonna log in and do my sequel Space hyphen.

  • You use her name is Bob.

  • Space hyphen P for the password, that's what.

  • Password supersecret.

  • 123456 And we're going to hit.

  • Enter.

  • We're now in hour.

  • My single database showed data basis just to make sure we know what databases we're dealing with.

  • The database that we care about today is this Class D B s.

  • So then we're going to go into Class D beast.

  • We do use Class B semi colon, Of course.

  • Now, in that database, we're going to show tables So we know what tables that we're dealing with.

  • We take a look and again we've been doing lots of demonstrations.

  • We've lost a lot of tables Table that we care about today is students again.

  • The reason that I go through this every time is when we are writing code, the computer cannot guess at what you mean the computer is not your mommy, right?

  • Your mommy.

  • If you ask your mom for something and it's not quite right, your mom will try to figure out what you mean.

  • Ah, computer is not your butt.

  • If you plug in their own word is just gonna fail, right?

  • So again, simple things like, Is that enable the table name students or is it named students?

  • Right.

  • If you misspell something like a table name, that could be a real problem.

  • S o The table that we care about today, though, is students That's we're gonna be searching through certain use described E S C students verify what the schema of this table looks like on DSO for the scheme of this table.

  • We have name, age, gender and uniforms.

  • So these are the column names.

  • We also have student idea here.

  • Ah, student I d is the primary key and it's the auto increment.

  • Basically, all I use a student i d.

  • For So I have an absolutely unique field for every single record.

  • So even if the names are the same, even the ages of the same, even the sexiest, saying at least a student, I d will be different so they don't run into major problems other than that.

  • Again, we take a look at name that is a text look at age.

  • That's an end like a gender.

  • That's a text and we look at uniform.

  • That's a text today, the fields that I'm going to be dealing with.

  • What I care about is name A and gender past that just to make sure there are records we're going to select all from students.

  • Just see what the records look like semi colon And okay, so we can see that we have got a lot of records in here.

  • It's kind of a mess again.

  • It's kind of, you know, we got Bobbie Sue Lucy.

  • You've got all kinds of different ages.

  • We've got different genders, got different uniforms thing.

  • The main thing that I'm looking here for is that I do have 19 records here, so I have something to play with again.

  • Yeah, you don't want to run into a problem where your search form isn't working because you have no records to Cirque against.

  • So we now all know this is here.

  • So let's go and take a look at the first Make the ml form that we're going to be dealing with S o.

  • I have created a form called surf dot html on if we look here again, this is a very, very, very, very basic 80 mil for so we're going to open up with an HTML tag, then we're going to go to the body.

  • So open up with a body tag.

  • We're then going to go down to the four.

  • So we opened with a form tag.

  • We given an action.

  • That action is then going to pass the information that we collect here to PHP uppercase s so search dot PHP.

  • So whatever information I gather here, this is going to be sent to this particular script.

  • The method is post.

  • So there is post and there's get again.

  • These are simple classes.

  • So we're just gonna use post.

  • You can figure out get layer from that.

  • We're simply going to have one feel we're simply only gonna have one field that field.

  • We're just gonna have a label colt search.

  • The input type is going to be text and in the name so that we can grab the value and turn that into a variable in PHP script.

  • This is how we identify this information.

  • We're going to call it search.

  • We're then going to break below that.

  • We're gonna have an input type of submit.

  • So basically, this is simply going be a submit, but in we're going to close our form, we're gonna close our body and we're gonna close our html If you go over and take a look at what that just physically looks like Goto 1 27.0 point 0.1 forward slash that PHP folder that I talked about before.

  • Forward slash asser a search duh h t m else and enter.

  • And so that's what this looks like, right?

  • So again, we've got a a horribly ugly, simple form.

  • So here is a search, right?

  • So we got certain figure search.

  • Here's a text box.

  • There's a text box.

  • Here's the submit button here, and here's a submit, but so this is simply what this looks like.

  • It is, Yeah, really ugly from that.

  • We're then going to go and take a look at the PHP script.

  • So this is what actually gets interesting.

  • So PHP of our case s for search dot PHP.

  • So we go over here and take a look at this script.

  • This is what we have right on and looks very similar.

  • Thio, what we've had before s so the first thing we're going to do is we're going to open up the PHP script then from that, what we have to do is we have to create a variable and set the value to that variables.

  • We're gonna create a variable called dollar Sign search.

  • So basically, just what the search result ISS we're going to make that equal to and then dollar sign underscore post.

  • And they do single quotation mark here, the single quotation mark and then simply the name.

  • So search.

  • So this right here, this right here that references this So whatever.

  • Whatever the hell name you give this text box you get, make a search, you could call it Billy Bo Bob.

  • I don't care what you call it.

  • Whatever this name is, that has to be this right.

  • That's this is where we create a P eight p variable and we set the value tow whatever the name is from that post.

  • So then we're going to go down and we're going to do our basic connections like we always have.

  • So we have dollar signs, server name, user name and password database.

  • Same thing we've done for the past.

  • Who knows how many classes again?

  • We're connecting to the local host because our my sequel database server is on the exact same machine as the Apache Web server user name and password to the user Name again.

  • At this point, you wanna root level User said that you don't run into permission issues.

  • We have that user named Bob eso Bob.