How to Create Registration Form in PHP With MySQLi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to day two of the three cursor I will teach you basics of PHP MySQL HTML and also how to create membership system in today video we are going to create registration form and also accept the informations from that registration form and save that information to the database so first we need to create website to registration form so basically our goal is to create this will be first name last name email password and for example register okay and then here on the table I will just show you how to create this document this form and only first name and sign on but other things i will show you on the computer so first we are going to define this document so it will be HTML ok now i'm not going to show you how to set title and other things because i want to keep things simple so i will show only how to create this form so are going to define body and inside body we are going to create our four so let's have all right here so form action action is basically where the data from this form will be sent to so it will be the name of our file so we will name this fun register.php register tdot php ok the next thing we need to define is to define the method of this form how data will be sent to method equal here you can write post let's say the second option is get depending on which you can use of those to define what you will use inside the PHP but i will show you that later so now we need to create this input so it will be input type of the input is text name so we can recognize this,this,this is different okay it will be first name and that's it and as I said here on the table only define this because it is different than all those so it is the type of the butt so input type is button value is what will be shown as a text on this but they all said as register register and that's it okay and now every opened tag needs to be cool so for is one type this and we need to close it so it's like this okay this backslash means it is now this / means it is closed okay now we need we have opened this body and we need to close it so like this okay and HTML is to open it and we are going to close it pretty simple right okay now i'm going to show you how in PHP we are going to accept all those informations so later can save them to the database so let's say this here is part of the PHP file so first we need to define file as a PHP PHP and we need to close it so let's say here okay everything here between those two will be represented as PHP code so as I said we have two types of the form and how data is sent so it is post and get in our example we used post okay so first we are going to define variable where we will store this first name so what is able is basically like container okay so first name equal and since we used post will look like this ok post first name okay first name same thing it will be for the last name email password and stuff like that submit button we really don't need to accept and later after we have used all those information we will store them to the database but later I will show you how we are going to do that but for now this is how we are going to create this form and how to assert all those informations let me show you now how we are going to create this on the computer so now once you understand what we need to do and how to create the basic website we are going to type code so i can show the final version so we are going to define HTML okay body our form that you already saw this register PHP method will post we need input type is text name will be first name that's it Oh put break let just copy these few times given in here last name email password for the password you will put it like password type so that we can see what you are typing and the last one is the button that we need okay so it is type of pattern and the value is register okay so now this is the basic form that we are going to have for our registration form so before before we even check this we need to run our server so I'm going to open terminal I have it here inside my phpstorm but if you don't have it and using linux like I do you can open it from the dashboard so I'm going say since I'm already position myself inside of lamp I will just write like xampp startapache and xampp step MySQL okay that's it now let's see how this looks like in browser so it's local host its membership system is inside members folder okay and we have nothing here so we are going to type register dot PHP and this is our for first name last name email password we can say he like placeholder first name placeholder last name email password let's see now this so i right click it will refresh ok because date i sent now we need to write PHP code that will asset this information so i will we can send it to some other file but we can stay inside the same i'm going to do it here so as we set first name equal post first name ok last name equal let me just copy pages ok so it's going to be email password and they don't need this one ok so it is password and it is email ok now if some data is sent we're going dust to output it to the browser so we can see what happens so let's say echo first name ok we can concatenate this string but let's put this so it will be for you much simple to understand what we are doing email and password okay let's test okay we got here empty because we have sent nothing but let's say first name last name email password registered okay now we have the data that we sent okay so pretty much that's it for this later we're going to insert this data inside the dailies before we move I want to write one condition which will decide is some data is sent or not because if we don't do that let's that's what will happened okay and so okay this is happening because we haven't defined any variables so we first going to say if isset and let's say first name okay and let's check now it's gone okay but if we do this okay i have deleted echo but just the c example okay there isn't problem but now we are going to see it data and that is the difference and why we use this condition to check if actually someone is pressed submit button we can do it even like this give some name to our register button and let's say register and here we are going to check this button so only if someone is pressed register button and this part here will execute so that's it for now i'm going to have to show you on the table how and which commands we are having SQL language and after that we are going to insert this data inside out database so now when we are created our form and website and also accept all the information from the form we need to insert our informations to the database so this is our table inside our database the one we named it users okay and now we want to store the informations from the registration to this database so before we move any further and i'll show you on the computer how we are going to do this from the PHP i want to show you only three commands inside the MySQL so first time will be how to insert something inside this table so the command that we are going to use is insert so we are going to write insert INSERT INTO users ok this is the name of our table okay this and we are going to define which cones we are going to insert so first one is first name first name next one is last name I will continue here the next one is email next one is password okay and now we need to define what is value of all those columns okay so VALUES and for the first name we will put let's say Senaid for the last name let me continue here yes okay email is hello CPI calm it doesn't matter really and the last one is password okay password is password it does matter okay and that's it this is the command in SQL language that we will just execute from our PHP code so once we execute this in the database will happen the next thing ID since if you remember is auto increment so automatically it will set to the one okay first name will be the data we have here so it's going here okay Senaid this is our last name so it's going here the same thing is going for the email and for the password they are going here and here ok so I'm not going to write because I want to keep this video very short ok so this is how we are going to insert something but how the next command I want to show is how we are going to check something into database does it exit also how to pull data from the database so the next command is SELECT from no sorry I'm steak select and now we are going to write which columns we want to select if we put like this this means we are going to select all those columns but if we don't want to do this we can write it like only selected which is always recommended way so we can see it first name and for example let's say email ok now we are going to say FROM this is going the name of the table again it is users ok from users ok and when we execute this query from this table we will select all first names and all emails so if we have thousands of users or millions it doesn't matter we'll select all first needs and all emails but if you want to define to select only for example one or some exact cut a row from the database we are going to say we're sorry WHERE and let's say ID I will continue here so you can see ID equal one okay so when we execute this query from the database from the PHP sorry we are going to select Senaid and email so once we execute we can we will see this it is first name, email ok and here will be Senaid and hello at it doesn't matter so that are 2 comments so let me clean this up so i will show the next command and the last comment i'm going to show is how we can change some data that already exists in inside our table so the command in SQL language is update UPDATE the name of the table which is users ok users SET and now we are going to write what you are going to change for example are going to treat first name ok first name equal let's say Senaid251 it doesn't matter really comma I will continue here what we else want to change for example let's say the user is updated his last name too so last name equal it doesn't matter surrender number and that's it we are not going anything to change this and if we are execute only this query that means that all users in the database will be updated so if we have thousand users thousand users who trade first name and the last name and we of course don't want to do that and now we need to again WHERE where and let's say ID equal one okay or we could set where email equal something but it's important that we use something some column that is actually unique in the database okay and that's it if we now execute this table will be updated and here won't be any more Senaid if you'll be 251 251 and that's it now this user is updating Davis so let me now show you how to use all those SQL queries inside PHP so now as I understand how to use and which commands we need to know for SQL language let's now connect to our database and insert this information inside the database so first thing is to connect so let's say connection equal new MySQLi are going to type up what is our server which is basically localhost we are going to write here the user name for this database we are going to write here the password which by default on xampp server is empty and we are going to type here the database which is membership system in our case ok the next thing is we need to escape all those inputs because that is recommendation to do always when you send some data from day from browser and store to database just in case that so on will not potentially put SQL in action and huck your database so we are going to put here connection real escape string okay so let me just copy paste this for all inputs and we need to close brackets okay and now we need from PHP to call the query that will actually insert this data inside the database so it's going to be data equal connection query and we are going to put inside query that we already know INSERT INTO users first name last name email sorry password ok VALUES this first name last name email and the last one is password so let's put test now will this being set inside the database so let's put something like first name last name email password click register okay let's now check what happens inside the database so we are open localhost PHP my admin that you already know click on the membership system and then on the user's table and now we can see that data has been started now we are going just let's see what will happen in case that we made some mistake inside this query for example we put users to instead of users so if you are going to try this as you can see user is not inserted inside the database but you actually have no idea that this happened so we need to have some way of how we can test that so we are going now to put here if data equal false echo let's say only connection error okay let's test this and there you go it said table membership system that users to doesn't exist which is what we want to do okay let me delete this so it's going to work and we are going to add here some short we know that data is inside so said the data has been inserted it doesn't really matter what is your message put any you like okay so let's test continue the data has been inserted and pretty much that's it for this registration form later I'm going to show you how you can use select and update comments for SQL language but for today we though this is it okay so I really hope so you like this video and if you have any questions please comment in our trees in facebook membership group so we can actually reach out and help you i hope you like bye bye
Info
Channel: Coding Passive Income
Views: 5,559
Rating: undefined out of 5
Keywords: how to create registration form in php with mysql, how to create registration form in php, how to create membership website, registration system php, how to become a web developer, php, create, php tutorials, php projects, tutorial, mysqli, php advance, registration, form, web developer, become a web developer, how to become web developer, mysql, becoming a web developer
Id: 8ybzMAOR-9M
Channel Id: undefined
Length: 24min 50sec (1490 seconds)
Published: Tue Oct 11 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.