I will call you back again to another video lecture in PHP.
In this video lecture, let's go ahead and learn how to accept input from a user in PHP.
All right.
So we know that PHP is a server side scripting language.
Therefore it needs the client side scripting language like HTML to be able to accept input from a user.
So what means is that you're going to create a HTML form where users can be able to input their username
or password and so on, and then they can be able to collect these and pass in that to PHP, which is
a server side scripting language, and move from there.
They can move that to the database.
So for us to be able to accept input from a user in PHP, it means we're going to write a small HTML
code where we can be able to just create a form, because we're going to use that form to impute the
user details.
Let's go ahead and create a form.
I'll go ahead and say form and I'll close this form.
All right.
Now I'm going to go right in here and give an action which is communicating with my PHP code.
Let's go ahead and say action.
So inside this action I'm going to tell the form, the PHP file that is going to act on the form that
I'm creating.
So in this case we are working on sites dot PHP.
So I will say site dot PHP.
That is the PHP file that is going to act on this particular form that I'm creating right now.
And the word I want is to get the, uh, information from this form.
So I'm going to create a method.
The method is going to be a Get method because I want to get information.
Therefore you are going to use a Get method.
Now if we be able to give this for an action to act on this, which is the site dot PHP and they're
using the method gate.
Go ahead and create a simple form right in there.
That is the input.
So I want users to input.
And the type of input I want right in here is going to be a text, because I just want you to input
your username.
Now I'll go ahead and say a name is going to be just username.
All right.
Go ahead and close this input tag.
Now whenever a user inputs his or her name you're going to need a submit button to submit that input.
Therefore you're going to create an A submit button.
So another input tag and this time around is going to be a submit.
Go ahead and create this input tag.
Now let's go ahead and refresh this I check it out.
So right now we have our form and we have the submit button.
Now, if I go ahead and say that my name is George, and if I had to submit these, you can see that
nothing happens.
We are not able to see anything.
I just submitted these and it went into the tint area.
I need to submit these using the PHP file.
Now I have to go back to my PHP right here just below here, and I'm going to type PHP to echo out,
voice out, whatever that I input inside that form.
So let's go ahead and say echo.
And then we'll go ahead and use the dollar sign underscore get because we are using the Get method right
in here.
And now I'm go ahead and input the name which is the user name.
So whatever name you input right in here is what I'm going to put down here.
So I'll go ahead and say echo add the username I'll go ahead and save this.
Now go ahead and refresh this again.
And you see that the George I input before has been printed out.
All right.
Now let's go ahead and input another one.
So I'm going to say Steve and go ahead and submit this now.
Steve is now a cut out.
So I basically get told to actually do this.
You understand.
So whatever.
Whenever a user puts them right in there I'll go ahead and be able to voice that out.
You can see that my PHP is now communicating with the, uh, the form I created.
Now let's go ahead and put a small prompt right in here.
So I'm going to say name and go ahead and save this refresh.
And you can see name.
So we call this know what the form is doing.
So go ahead and say um this is uh George Steve and click on submit I have George Steve printed out.
So if you want to input something like a name let's go ahead and say what are the name.
Go ahead and put a break tag right in here.
And I create a new c h I'm going to say what to add H.
You understand.
So go ahead and say input.
And the type is going to be numbers.
You understand.
It's is known to be a text because we are dealing with numbers right now, so we'll go ahead and give
it a name.
Always give a name and whatever your inputs here, name, whatever you insert inside that name is what
it's going to give.
PHP.
So if I put H or anything inside there, I'm going to let PHP know that this is what I'm working on.
You understand.
So go ahead and close that and I'll go right inside PHP and say echo and uh dollar underscore get.
And then you go ahead and put in H.
Save this and let's refresh this and check it out.
So it says we have a syntax error right in here.
So what actually happens right here is that I just want to echo this out.
Go ahead and copy this.
So I want this to be another stove right in here.
Then go ahead and say so save this right now refresh this page.
And uh we have name we have age.
So if I go ahead and say name is hello and age is 20 and click on submit, we have hello 20.
So you can see that.
So we have hello 20.
So I have two PHP uh tags right in here.
If first one is echoing the username the second one is echoing the age.
As you can see, our form is actually working fine.
So let me say I want the 20 to be below.
Go right in here after this PHP five and see I create a break tag.
And let's go ahead and refresh this.
And you can see that 20 has gone below.
Now you can go ahead and make these customized a little.
Let me say I want this guy and see your name is okay.
Your name is.
And uh, the second one Your age is 70s.
And let's refresh this and check it out.
So your name is hello.
Your age is 20.
So your name is George and your age is 24.
So I check it out.
Your name is George.
Your age is 24.
You can be able to see that right in here.
So this is a way of accepting input from a user is in PHP.
And for every form you create in HTML, you can see that we can actually use PHP to get the inputs from
the user.
And you can now move those inputs to our database.
Right now we are not talking about database.
That is why the input is just displayed on the screen, because you don't need to put this input on
your screen.
So when we talk about database then we'll go ahead and learn how to take this input and move them to
the database.
So for now practice with this.
Check it out.
And if you have any question on this use the question and answer section.
And I'm going to get back to you as soon as possible.
Thank you so much.
And I'm going to see you in the next video lecture.