Transcripts
1. Introduction: does anyone appearing in water that comes with a eliminar initialization compared? And they said your muscles are my way that I mean compared.
2. Create Database and Save Data Beginning: Good morning friends, my name is Edward Vidal and in this tutorial I am going to show you how to save in bases
00:00:07.400 --> 00:00:18.000
data with PHP and MySql, what we do is open the XAMPP Manager to
00:00:18.000 --> 00:00:20.000
activate Apache and MySql.
00:00:20.900 --> 00:00:32.700
So we wait for it to open, so here we activate Apache, I already have them active, and activate MySql, then
00:00:34.200 --> 00:00:42.500
what we do is open phpMyAdmin and we are going to create the database and the table, the database will be called "test"
00:00:42.000 --> 00:00:44.800
create TEST DATABASE;
00:00:45.400 --> 00:00:52.800
we are going to use test; and I'm going to create a table that will be called "users"
00:00:55.501 --> 00:01:08.700
it will have four "id" fields that will be the primary key "names" of type varchar and not null
00:01:09.101 --> 00:01:11.600
To make it mandatory to fill it out.
00:01:11.601 --> 00:01:14.500
"surnames" which will be varchar
00:01:19.801 --> 00:01:34.300
Done and we are going to put a "mail" of type varchar and not null to make it mandatory
00:01:34.301 --> 00:01:36.400
so
00:01:36.401 --> 00:01:44.500
I close the parentheses and give it to continue, determine, and here we have our table created, we can see the structure
00:01:44.501 --> 00:01:52.500
with the four fields, so what I'm going to do next is make the design with Materialize
00:01:52.501 --> 00:01:54.900
which is a quick way to design.
00:01:55.102 --> 00:02:00.300
then I'm going to download Materialize, I'm going to downloads
00:02:02.902 --> 00:02:14.000
I'm going to unzip it and it's going to be called "php save"
00:02:17.902 --> 00:02:32.500
as it already exists I am going to call it "guardaphp", that's it, then I am going to take this folder to the "XAMPP / htdocs" folder and save it here and
00:02:32.502 --> 00:02:39.200
I'm going to drag it to sublime text, I'm going to drag it here
00:02:41.402 --> 00:02:42.400
It didn't fit!
00:02:46.703 --> 00:03:03.000
here again, ready, then what I'm going to do is create a new file and I'm going to call it "index.php", here the materialize
00:03:03.203 --> 00:03:12.400
it does not show a structure as it should be, so I am going to copy it and paste it here, inside "body" rd that I am going to insert my entire form
00:03:13.003 --> 00:03:14.200
I'm going to create a "section.contents"
00:03:17.103 --> 00:03:31.300
and here I am going to create a title, I am going to call it "Create Users", then I open it to see how it looks
00:03:34.903 --> 00:03:36.300
the file is called
00:03:40.103 --> 00:03:44.200
localhost/guardaphp/
00:03:47.103 --> 00:03:50.800
and there we see what we carry.
00:03:51.104 --> 00:04:01.500
Then we are going to Materialize in "Components" we are going to look for the forms, I am going to select this form that is here
00:04:02.804 --> 00:04:18.800
I copy and paste here, paste this one, and here I will copy this "div" again and paste it, then I will change the names, this would be
00:04:21.304 --> 00:04:26.900
"Identification, this would be" Names "
00:04:29.604 --> 00:04:34.500
"Surname" and "Email" and in the input
00:04:34.904 --> 00:04:36.600
this would be "number", this would be
00:04:39.004 --> 00:04:40.500
"text"
00:04:44.904 --> 00:04:50.600
and this would be "email".
00:04:50.904 --> 00:04:52.100
we can erase this.
00:04:54.204 --> 00:04:58.100
This also to make the code shorter
00:05:01.405 --> 00:05:02.400
this too
00:05:05.105 --> 00:05:12.600
this also, we are going to delete all the id that do not interfere in the code and do not affect us
00:05:15.905 --> 00:05:22.400
then we delete this one, save it and let's see how the form is.
00:05:22.405 --> 00:05:29.000
There it is working, what I am going to do is change the icon, I am going to put this one here
00:05:32.505 --> 00:05:43.800
here I am going to put a #, this one I am going to leave like this and to this "email", I save, then there I changed.
00:05:44.205 --> 00:05:56.700
So what I'm missing would be a button, so I'm going to copy this entire div and I'm going to delete what's in here
00:06:00.806 --> 00:06:02.400
I'm going to add a button of type
00:06:05.406 --> 00:06:17.700
"submit", I am going to put a class that is in "CSS / buttons" and I am going to add this class that is here which would be this.
00:06:21.506 --> 00:06:27.400
I add this class and add the icon
00:06:31.106 --> 00:06:42.400
I added it here and here I am going to put "save", then I save, update and here I have the designed form, right now
00:06:42.406 --> 00:06:51.400
We do some styling, ready, then we will continue creating a folder I will call it "config"
00:06:51.506 --> 00:06:59.500
I am going to add a file that is going to be called "connection.php", it is the one that is going to connect.
3. Save Data in MySQL Part 2: It will connect with our Apache, our database, so here I am going to create four variables: "host" that you see connecting to the local host
00:00:09.900 --> 00:00:10.600
localhost
00:00:13.600 --> 00:00:18.900
Here I am going to add user that would be "root" by default
00:00:21.200 --> 00:00:29.600
here I am going to add password that will be empty and the database that is called "test", I am going to create another variable that goes
00:00:29.600 --> 00:00:41.200
call connection that will be the same as "mysqli", which is a method that receives four parameters, which would be the ones here,
00:00:42.200 --> 00:00:48.000
to bind everything from localhost, with the database and password
00:00:54.700 --> 00:00:59.900
we save, we return for this form.
00:00:59.901 --> 00:01:09.600
So here we are going to start from the form that would have the method as we are going to send the data that would be "post"
00:01:09.601 --> 00:01:17.500
and the action who is going to perform the function, which would be "index.php" and we are going to name all the
00:01:17.501 --> 00:01:24.000
input and the button, the name will be "txtid"
00:01:24.401 --> 00:01:29.100
I'm going to call this one "txtnom"
00:01:31.901 --> 00:01:49.800
I'm going to call this one here "txtape" and I'm going to call this one "txtemail", I'm going to call the button "btnguardar", that's it, then at the end we can start with the programming
00:01:50.301 --> 00:01:57.400
in this case we are doing it in a structured way, everything goes within the same HTML.
00:01:57.402 --> 00:02:06.200
So here I am going to select PHP to recognize the PHP tags for me, I am going to create a. sorry!
00:02:06.502 --> 00:02:16.700
I am going to include the connection, the file called "connection.php" is inside the "config" folder.
00:02:16.802 --> 00:02:23.300
Here we are going to create the variables that we have that would be identification.
00:02:24.202 --> 00:02:34.200
We put "POST ['txtid']"
00:02:36.602 --> 00:02:47.300
here we put "POST ['txtnom']", here it would be "POST ['txtape']"
00:02:51.103 --> 00:03:03.000
and finally email would be as we named them above which would be "POST ['txteemail']", ready
00:03:03.103 --> 00:03:07.000
Here I am also going to create the variable of the button that I am going to call save which is equal to
00:03:10.603 --> 00:03:21.700
"POST ['btnguardar']", then here we begin the process to save, we tell them that if we click the Save button.
00:03:21.903 --> 00:03:23.300
What is going to happen ?
00:03:23.303 --> 00:03:36.200
A SQL variable has just been created, I'll tell you to insert the information in the users table and the values
00:03:36.303 --> 00:03:47.200
will be the following, then I'm going to show you, as this is integer, the integers go without quotes, then this would be
00:03:47.204 --> 00:04:05.700
without quotes, we close, that would be with quotes we closed, ready, then here we say
00:04:05.804 --> 00:04:11.700
this is how it is executed, I am going to create a variable that I am going to call "execute" and we send the query
00:04:14.604 --> 00:04:24.600
execute is equal to the connection variable that we create in the connection file, this connection variable
00:04:25.504 --> 00:04:32.000
We send you the SQL query, if it runs successfully.
00:04:33.104 --> 00:04:44.600
then I'm going to send a message, but I'm going to send it nicer with Materialize a "JavaScript / Dialogs"
00:04:45.904 --> 00:04:47.400
I will send
00:04:47.805 --> 00:05:01.500
I'm going to send this one from here, then I copy it and it must go inside a script tag, I paste it, close the script and here
00:05:01.505 --> 00:05:03.300
we change the content.
00:05:03.305 --> 00:05:12.600
Then I am going to tell him to say: "Saved correctly" and here I am going to tell him that I have another class that is green
00:05:14.805 --> 00:05:22.700
if not saved, then send us an error message
00:05:25.305 --> 00:05:29.800
and the class is going to be red.
00:05:29.005 --> 00:05:39.800
We save, update, then this error does not appear but we can control it, they tell us that the variables the names
00:05:39.805 --> 00:05:47.400
are not defined and we know that they are correctly, so what we do is control
00:05:47.405 --> 00:05:52.400
that error that does not seem we are going to say "error_reporting (0)"
00:05:52.905 --> 00:05:58.600
We save, update and test our code.
00:06:00.106 --> 00:06:08.900
I'm going to give it to save, then here it says saved correctly
00:06:08.906 --> 00:06:17.400
We are going to verify in the database if it was saved correctly and here we can see that they were saved
00:06:17.406 --> 00:06:18.000
the data correctly.
00:06:22.206 --> 00:06:28.800
Well friends then here we end for today and I wait for you in the next video that would be to consult data
00:06:28.906 --> 00:06:31.700
with PHP and MySql, see you soon!
4. Query Database Data with Php7 Beginning: This time what we will do is search for data and edit with PHP and MySql, from the crud
00:00:08.500 --> 00:00:15.700
what we have done has been to create the option to save, which we have done in the previous videos.
00:00:15.800 --> 00:00:25.200
This time what we are going to do is "read" and "update" which would be to consult the data from the database and update them.
00:00:25.200 --> 00:00:28.800
I remind you again that we are working with the materialize framework
00:00:29.400 --> 00:00:36.800
So I already have it downloaded, we can download it directly from the official materialize page
00:00:38.500 --> 00:00:40.100
and let's get started.
00:00:40.100 --> 00:00:51.900
I also remind you that this folder must be saved inside the local disk C in "XAMPP / htdocs"
00:00:51.000 --> 00:00:55.500
here is the folder.
00:00:55.501 --> 00:01:01.000
I already have active in Apache and MySql, to open the file, then
00:01:02.401 --> 00:01:10.200
I remind you that we write localhost, the name of the folder and the file that I want to view; here we are going to start
00:01:12.601 --> 00:01:18.600
with the materialize structure that I find on the official page.
00:01:18.901 --> 00:01:28.800
I am going to download here I have copied, I paste, I am going to put a title "Edit and search".
00:01:29.401 --> 00:01:38.300
We are going to work here, here we can see the title so we are going to start in components we are
00:01:38.301 --> 00:01:39.500
with the form
00:01:42.601 --> 00:01:49.800
I'm going to use the first form, this one from here
00:01:54.502 --> 00:02:09.000
I'm going to put the entire form and I'm going to remove what I don't need.
00:02:10.102 --> 00:02:15.200
I don't need this, this one here that is repeated
00:02:17.702 --> 00:02:24.900
this one either, I remind you of the database that is this! test "
00:02:24.902 --> 00:02:34.600
Users, I already have two records that would be identification names, surnames and email, so here I am going to remove all
00:02:34.902 --> 00:02:45.400
these, I'm going to leave this "div", then in this "div" what I'm going to do is
00:02:50.103 --> 00:03:06.700
id I'm going to remove this and it would be "number" the id and inside of this div
00:03:07.403 --> 00:03:16.900
I'm going to remove this div from here and I'm going to close it here.
00:03:18.603 --> 00:03:27.900
Inside this "div" I'm going to create another one that would be identification, names, we can also remove this since
00:03:28.103 --> 00:03:35.700
not necessary, it does not affect our code. So it's Identification, Text type name
00:03:39.603 --> 00:03:50.200
I'm going to delete this one too and what I'm going to do is create first
00:03:52.904 --> 00:04:08.000
I am going to create another "div" with the other two columns that would be identification, names, surnames of type text and email from
00:04:08.004 --> 00:04:16.400
type email, save and update the page and here we see the form.
00:04:16.504 --> 00:04:20.800
Let's give it a title that would be
00:04:23.404 --> 00:04:26.300
"Manage Users"
00:04:26.904 --> 00:04:32.100
There it is, here inside this "div"
00:04:34.704 --> 00:04:48.300
we have a "div" that has two columns and this one another "div". Here at the bottom I am going to create another "div" that would be to search.
00:04:48.704 --> 00:04:53.200
Here what I'm going to do is I'm going to copy this one
00:04:56.305 --> 00:05:02.800
and I'm going to organize it, here I'm going to look for identification
00:05:05.605 --> 00:05:10.800
and this would be a button of type "submit"
00:05:15.405 --> 00:05:24.800
we are going to put a button of type "submit" and I am going to call it "Search".
00:05:25.105 --> 00:05:42.800
This is how it will work, we are going to put a class to make the button more elegant, we are going to put this class here.
00:05:48.305 --> 00:05:49.400
let's put it here.
00:05:55.706 --> 00:06:04.100
ready, we save and that would be the search form.
00:06:05.906 --> 00:06:09.100
Here we can put a division.
00:06:12.706 --> 00:06:17.400
and here we are going to put a button at the top to divide
00:06:21.406 --> 00:06:22.600
we are going to put this same button
00:06:27.106 --> 00:06:35.000
we're going to put it here and this would be the save button.
00:06:36.006 --> 00:06:41.300
In this case it will not work because we are focused on the Search button
00:06:47.806 --> 00:06:53.800
We see it here, I'm going to change the color.
00:06:57.007 --> 00:07:03.400
Ready, let's search by identification and we already have it
00:07:03.407 --> 00:07:05.500
Here we already have the designed form.
00:07:08.307 --> 00:07:14.400
We are going to put a title here that will be "Consult users"
00:07:17.607 --> 00:07:21.800
Ready, then we are going to put this button to work.
00:07:21.907 --> 00:07:34.900
We are going to name the labels, I am going to call the button "btnfiltrar" and I am going to call this one "txtbus" and
00:07:35.107 --> 00:07:41.500
I remember that for the buttons to work, they must be enclosed within the "form" tag that opens here.
00:07:41.507 --> 00:07:51.200
I'm going to open it at the beginning of the "body" and I'm going to close it here.
00:07:51.208 --> 00:08:00.900
In addition, for everything to work, you must have the method with which the data will be sent and the action that tells us which form
00:08:01.208 --> 00:08:03.000
going to execute
00:08:03.508 --> 00:08:04.800
What we are doing.
5. Query Database Data with Php7 Continuation: here we are going to start programming, the search button first of all and the filter button.
00:00:13.100 --> 00:00:19.200
I'm going to program it here, I'm going to put PHP in it.
00:00:20.200 --> 00:00:26.300
We are going to change here so that it does not recognize the labels and here we are going to program we are going to include the
00:00:26.300 --> 00:00:28.600
Connection.
00:00:28.600 --> 00:00:32.000
I think I have not shown them, that it would be this, the same as the previous video.
00:00:34.200 --> 00:00:46.000
And here we are going to say the folder and the connection file, I am going to create the variable to find what it would be
00:00:46.600 --> 00:00:55.900
put POST and the name of the input, here I am going to call the search button
00:00:55.901 --> 00:01:02.900
Same name "btnfiltrar" and here we are going to program the search
00:01:08.301 --> 00:01:12.800
Ready, here we are going to search.
00:01:13.101 --> 00:01:23.900
We are going to create a variable that I am going to call "sq" and I am going to tell it to select everything from the table.
00:01:23.001 --> 00:01:25.700
Here we have it, users
00:01:28.701 --> 00:01:29.300
where
00:01:34.301 --> 00:01:47.800
the id is equal to, let's see if it is integer or varchar, it is of type integer, so it goes without quotes, then
00:01:47.901 --> 00:01:52.100
Here what I am going to do is send the variable "bus"
00:01:54.702 --> 00:02:10.200
We execute with the connection variable that I have in this case and we pass it the query that would be "sql"
00:02:10.402 --> 00:02:11.400
so here I'm going to create a table
00:02:14.802 --> 00:02:16.400
"threw out"
00:02:19.802 --> 00:02:24.400
let's put a class "bordered"
00:02:27.902 --> 00:02:34.800
We can get these classes out of materialize, in this part of here.
00:02:34.902 --> 00:02:49.300
Let's see it is in CSS, here we can get the classes that we have the different types of tables and here
00:02:49.402 --> 00:02:50.600
I'm going to put
00:02:54.002 --> 00:02:55.300
the headers
00:02:57.703 --> 00:03:00.200
then I'm going to tell him to have "th"
00:03:06.203 --> 00:03:16.100
which would be Id, I close "th", first of all is the column "tr", sorry! , the row.
00:03:16.903 --> 00:03:21.800
We continue, 1, 2, 3, 4.
00:03:22.603 --> 00:03:30.400
We close the "tr", ready. Here it would be identification, names,
00:03:34.103 --> 00:03:41.200
surname and email.
00:03:42.303 --> 00:03:49.500
Here we are going to go through a "while", I am going to create a variable "rows"
00:03:49.503 --> 00:03:59.400
We are going to go through with a "while", all the data that we brought from the base while I relate rows to the
00:03:59.404 --> 00:04:08.800
run variable and the "fetch_row" method, what brings us are the number of columns we have in the query.
00:04:09.404 --> 00:04:22.200
Here in another "tr", here I am going to go through all the rows, all the columns, so here I put an "echo"
00:04:23.104 --> 00:04:30.400
not "tr" but "td"
00:04:31.104 --> 00:04:51.300
So in row zero, true "td" and it starts at zero, one do, three, here I am going to close the table.
00:04:53.804 --> 00:04:57.300
"echo" table, and here I close it
00:04:57.505 --> 00:05:00.900
So let's run the code, let's test it.
00:05:02.405 --> 00:05:04.900
Here we get some small errors.
00:05:08.105 --> 00:05:18.000
Here they tell us, here in the errors it tells us that they are not defined but we can
00:05:18.005 --> 00:05:21.600
control with "error_reporting (0)" method
00:05:22.105 --> 00:05:25.900
I save, update and
00:05:26.305 --> 00:05:30.400
Here we see that it no longer appears to us, so we will see if it works.
00:05:30.405 --> 00:05:36.600
I have a 1020 ID.
00:05:36.005 --> 00:05:39.100
So, we are going to give you search
00:05:41.505 --> 00:05:44.800
Then see that in this part the 1020 appeared to us
00:05:48.205 --> 00:05:55.600
ready.
00:05:55.906 --> 00:06:03.000
What we are going to do here is create a button called select.
00:06:03.106 --> 00:06:03.500
Here
00:06:08.506 --> 00:06:14.400
There are many ways to do it, but I really like this way, I'm going to call it "Select".
00:06:14.406 --> 00:06:19.700
It seems very practical to me, and here I am going to create a button of type "submit"
00:06:23.806 --> 00:06:30.600
I'm going to call the name "btnseleccinar"
00:06:33.406 --> 00:06:35.700
So here I am going to call you
00:06:40.206 --> 00:06:41.400
I'll put
00:06:45.606 --> 00:07:51.200
an icon labeled "i"
00:06:51.206 --> 00:06:56.400
All this is in materialize.
00:07:00.407 --> 00:07:02.400
I close the "i".
00:07:02.807 --> 00:07:05.200
Let's see if it's "edit"
00:07:10.507 --> 00:07:14.100
there's the select icon; this is the only thing going to do
00:07:14.107 --> 00:07:23.600
when you click it bring the data to the form to edit it; then here to the button I'm going to put this class
00:07:29.607 --> 00:07:37.800
I'm going to put this class on the button so that it is colored, I change the quotation marks, it will no longer be black.
00:07:37.807 --> 00:07:40.100
Let's put a blue on it
00:07:43.507 --> 00:07:51.600
Done, there it is, we are going to program the select button to bring me the information to select
00:07:51.007 --> 00:07:54.200
to text boxes for editing
00:07:56.808 --> 00:08:04.800
here what I'm going to do is I'm going to program this button.
6. Query Database Data with Php7 Finish: First I'm going to create the button, then I'm going to call it "select", which will be equal to POST ['btselect]
00:00:25.600 --> 00:00:26.300
I am going to tell him
00:00:35.800 --> 00:00:39.300
I'm going to tell you to select
00:00:42.100 --> 00:00:47.200
all of users where the id is the same
00:00:54.500 --> 00:00:55.000
to "bus" no, sorry "to
00:00:59.000 --> 00:00:59.800
to select
00:01:15.501 --> 00:01:17.700
to select.
00:01:17.001 --> 00:01:30.000
What we are going to do here is create a variable and I am going to call it "rows" and I am going to tell it again to execute
00:01:32.901 --> 00:01:34.000
query
00:01:36.001 --> 00:01:36.900
sql
00:01:41.301 --> 00:01:48.000
Here we missed something very important, which is when you click the button, to know which button is executing.
00:01:49.002 --> 00:02:03.300
If I click on the search button, what it will do is this part here
00:02:08.202 --> 00:02:11.300
You will go through the query that I am giving you here
00:02:14.102 --> 00:02:15.500
up here
00:02:20.702 --> 00:02:27.100
So I'm going to put this here so that it shows us the table only if you query, when you click the query button.
00:02:37.002 --> 00:02:54.500
and if we click the select button, this part will be done here.
00:02:57.403 --> 00:03:10.500
So here what we are going to do is that this variable "rows" we are going to go through in each of the inputs, then I am going to
00:03:10.503 --> 00:03:30.900
say here to show us the php value, print rows in column zero.
00:03:30.903 --> 00:03:36.700
In column 1, 2 and 3 here I need to close, let's see what I have bad!
00:03:50.503 --> 00:03:51.000
semicolon
00:03:54.603 --> 00:03:58.200
and it closes here
00:04:01.504 --> 00:04:16.300
Here
00:04:24.904 --> 00:04:27.600
We have an error here, let's see what we have
00:04:30.904 --> 00:04:31.700
php echo
00:04:34.304 --> 00:04:43.500
here is fine.
00:04:44.504 --> 00:04:52.300
this was a mistake, but we have another
00:04:56.405 --> 00:05:04.200
what else do we have? This one here !, I needed to close the php
00:05:07.105 --> 00:05:07.700
ready.
00:05:07.705 --> 00:05:10.600
I'm going to save and I'm going to update.
00:05:12.905 --> 00:05:19.700
So here it tells me that they are not defined, the same did not happen to me in the id.
00:05:19.705 --> 00:05:25.600
This is because it tells me that the rows variable is not defined but I already have it created, so what
00:05:25.605 --> 00:05:31.100
I'm going to do, is pass this one "error_reporting (0)", I'm going to pass all the code up
00:05:34.505 --> 00:05:38.800
so that the "error_reporting (0)" is first and the error does not appear
00:05:47.205 --> 00:05:55.200
but I'm going to pass this one and the one in the form table; the only thing I need this above is the "error_reporting (0)", this part of searching
00:05:55.206 --> 00:06:09.600
if I can put it in the final part; I'm going to save, I'm going to update, if I type 1020 and select the "Search" button, then here I am
00:06:09.706 --> 00:06:12.100
appears and if I click on "Select"
00:06:14.806 --> 00:06:24.700
we are going to go through an error that is very clear, which is that this select button is not inside the label
00:06:24.706 --> 00:06:31.900
"form", then it is not running on the form.
00:06:31.906 --> 00:06:43.900
We are going to save it inside the "form" tag, we are going to update, select and nothing happens to me, what I am going to do is test, I am going
00:06:43.906 --> 00:06:45.100
to tell him here
00:06:49.506 --> 00:06:53.400
here we have an error that I can not pass the button, but
00:06:57.007 --> 00:07:08.200
I have to do something, I am going to create a session variable, I am going to put "session_start"
00:07:08.207 --> 00:07:09.400
and here I am going to create a session variable
00:07:12.407 --> 00:07:20.300
to know which row is row zero, to save row zero in a session variable, then here I am going to call it
00:07:21.007 --> 00:07:32.600
I'm going to call it "id" and this would be row zero.
00:07:32.807 --> 00:07:47.100
This session variable is the one that I am going to look for at the top, so we are going to update.
00:07:47.107 --> 00:07:53.200
It tells us that it cannot be encapsulated, so I have to remove these quotes.
00:07:53.708 --> 00:08:03.200
Here we have another error, which here is the "fetch_row" method, to go through the columns, I update.
00:08:03.908 --> 00:08:18.400
We are going to type 1020, search, we are going to select the data, nothing happens yet.
00:08:18.408 --> 00:08:19.100
Let's look
00:08:21.808 --> 00:08:29.500
already, is that this "session_start" must be at the beginning because I am using this session variable.
00:08:29.508 --> 00:08:40.100
Let's put it over here, let's look again; that was the error, ready, here what I have to do change the data that
00:08:40.108 --> 00:08:57.000
It would be, 0, 1, 2 and 3; then I update then there it will show me, identification, name; If I look for 1021 I have two
00:08:57.009 --> 00:09:03.700
I click on search, there it already appeared, then I click on select and the other one I have will appear.
00:09:03.709 --> 00:09:08.000
I will verify in the database, which would be this.
7. Edit Data in Mysql with Php7: Now we are going to program the edit button, so here I am going to tell you.
00:00:09.300 --> 00:00:28.000
This button, I am going to remove it, I am going to put php, but I am going to leave it here; I will say that if the variable "rows" is greater than zero
00:00:30.200 --> 00:00:44.500
if it is greater than zero, it is because the select button was clicked and it prints
00:00:44.700 --> 00:00:55.900
the button, which prints the button, this touches put it in single quotes.
00:00:56.900 --> 00:00:57.500
Too
00:01:01.001 --> 00:01:06.200
I'm going to call this button "edit"
00:01:09.001 --> 00:01:14.100
There we are going to update, there it is.
00:01:14.101 --> 00:01:18.400
We are going to see the process from scratch, then the button does not appear
00:01:21.601 --> 00:01:31.300
we are going to put it but it shows us the save button only, then here it should save
00:01:35.201 --> 00:01:37.000
there is the save button, but if I search
00:01:41.601 --> 00:01:46.300
I'm going to click select, the save button no longer appears, but the edit button.
00:01:46.301 --> 00:01:54.300
This is the one that we are going to program and we are going to give it a name "btneditar"
00:01:57.502 --> 00:02:03.100
I can program this one, I'll put it here at the end
00:02:06.502 --> 00:02:11.600
sorry! here I am going to tell you
00:02:15.402 --> 00:02:18.300
I'm going to edit, I'm going to create the edit variable
00:02:23.302 --> 00:02:32.800
"btneditar" and here I am going to create the variables
00:02:33.202 --> 00:02:36.000
First I'm going to put the names
00:02:40.502 --> 00:02:40.000
"txtid"
00:02:45.002 --> 00:02:47.300
"txtnom"
00:02:50.503 --> 00:03:05.300
"txtape" and this one "txtemail", then here I am going to save them in id variables that will be equal to
00:03:08.603 --> 00:03:10.100
"txtid" this will be
00:03:17.603 --> 00:03:19.500
"txtnom"
00:03:23.503 --> 00:03:24.000
this is going to be "txtape"
00:03:27.903 --> 00:03:29.300
and this
00:03:29.403 --> 00:03:34.400
"txtemail"
00:03:37.003 --> 00:03:49.600
Ready, so here I tell you that if I click the edit button what it will do is
00:03:52.904 --> 00:04:03.200
the same, we are going to send the query to the database that would update the user table.
00:04:03.304 --> 00:04:04.900
Field
00:04:07.404 --> 00:04:07.900
Name
00:04:11.704 --> 00:04:16.000
for which I send you here, which would be "nom"
00:04:17.704 --> 00:04:23.900
Let's see how it is in the database, name, surname and email.
00:04:24.104 --> 00:04:27.500
How is it in the database names, surnames
00:04:31.004 --> 00:04:34.900
and mail
00:04:45.004 --> 00:04:47.900
names, surnames and email.
00:04:47.904 --> 00:04:51.900
And here I am going to put it email, sorry!
00:04:55.404 --> 00:04:56.100
where
00:04:59.405 --> 00:05:08.100
If I suddenly made a mistake in the identification, it can be modified.
00:05:08.505 --> 00:05:11.700
Suddenly I was doing the registration and I was wrong.
00:05:12.805 --> 00:05:24.200
So here what I am going to do is "id" and since it is an integer type then it will go without quotes and the rest between quotes where
00:05:24.605 --> 00:05:27.100
the id is equal to
00:05:27.205 --> 00:05:38.500
the session variable is here that is the selected user.
00:05:38.505 --> 00:05:53.000
Here we execute with the connection variable, we send the query, the query and here we say yes
00:05:53.606 --> 00:06:01.400
Here we can put this to validate, that if it is executed correctly.
00:06:01.406 --> 00:06:14.700
Here he sends us a message, this is from materialize, it is in "JavaScript / Dialogs"
00:06:16.406 --> 00:06:19.100
I'm going to send you this one from here
00:06:21.706 --> 00:06:22.100
it is not this one.
00:06:28.006 --> 00:06:35.100
that must go inside a script tag, for it to run correctly
00:06:37.606 --> 00:06:43.100
the script and here I am going to tell you
00:06:45.906 --> 00:06:57.300
updated correctly and I am going to put another class here, the color green and here I am going to say that if not
00:06:58.207 --> 00:07:02.600
that sends us the message of
00:07:07.207 --> 00:07:15.600
"Updated error" and the color red, let's update.
00:07:15.907 --> 00:07:23.400
Here they tell us that there is an encapsulation error, which would be here as we saw previously, we update
00:07:26.407 --> 00:07:32.700
Ready, here I'm going to put "Ospina", I'm going to click edit
00:07:35.607 --> 00:07:41.600
It didn't work for us! , let's see what happened.
00:07:43.007 --> 00:07:51.300
One thing I do is print the variable "sql! To know what data we are sending
00:07:53.107 --> 00:07:58.000
and we do the whole process, then we type 1020, search
00:08:00.908 --> 00:08:12.300
select, enter "Ospina", select edit and if it does not appear, we will see what errors we have
00:08:19.008 --> 00:08:29.600
now, the error is that I did not name it "btneditar", ready, we update
00:08:33.008 --> 00:08:36.700
and we do the process again, 1020, we click on search
00:08:39.308 --> 00:08:40.300
we click on select
00:08:43.408 --> 00:08:53.200
We click on edit, then "updated correctly" appeared and here it printed the query that we were
00:08:53.208 --> 00:08:59.000
sending, we can remove this.
00:09:01.409 --> 00:09:07.600
We update here, so we are going to search to see if it updated us correctly.
00:09:07.709 --> 00:09:22.700
We click on search, then there is "Edward Vidal Ospina", ready, that was all for today, for the next class we are going
00:09:22.709 --> 00:09:29.900
To do is the delete button and we will continue working on many things that PHP has.
00:09:29.909 --> 00:09:31.200
bye
8. Login with Php7 Beginning: This time what we are going to do is create a login form with PHP and MySql, then
00:00:11.300 --> 00:00:15.400
The first thing we are going to do is go to Materialize
00:00:18.300 --> 00:00:20.600
What is helping us to do the Frontend design
00:00:21.400 --> 00:00:23.300
We are going to download this folder
00:00:28.100 --> 00:00:33.500
We unzipped it, I'm going to change the name, I'm going to call it
00:00:35.000 --> 00:00:50.100
"initiate session", I copy and paste it in the "XAMPP / htdocs" folder and dragged it to sublime text, then here I am going to create a
00:00:50.100 --> 00:00:55.500
file I will call it "index.php"
00:00:55.801 --> 00:00:00.900
or I'm going to call it "start.php", I save it.
00:01:07.101 --> 00:01:13.700
and here I am going to create the structure of the page that is over here
00:01:20.401 --> 00:01:27.900
ready, so here I am going to create the login form, I am going to base myself on Materialize
00:01:32.501 --> 00:01:35.600
I'm going to base myself on this form that is here
00:01:40.901 --> 00:01:49.900
and I am going to change this here for username and password.
00:01:50.301 --> 00:01:58.600
This here we can delete, this too, this will be of type "password"
00:02:04.502 --> 00:02:16.600
This will be of type "text", we can leave it like that, and what we will do is add a button, so here I am going to create the button of type
00:02:19.502 --> 00:02:23.000
"submit", will have a
00:02:25.502 --> 00:02:30.800
class that we are also going to take from Materialize
00:02:33.702 --> 00:02:35.200
what would this be here
00:02:43.602 --> 00:02:54.500
and it will have a text that will say "save", ready then what we do is open the project that we are
00:02:54.502 --> 00:02:56.900
developing.
00:02:57.803 --> 00:02:06.100
localhost / login / index.php
00:03:06.203 --> 00:03:07.800
Let's see where I went wrong.
00:03:13.503 --> 00:03:14.100
Start.php
00:03:19.203 --> 00:03:20.900
Ready, there we already have the form.
00:03:20.903 --> 00:03:33.900
We are going to give it a title, but first of all, I am going to enclose it here within a "section.contents" to give it a bit of design
00:03:34.103 --> 00:03:47.100
here I am going to put the title "Login", then in this style sheet I am going to call it
00:03:47.303 --> 00:03:48.200
styles.css
00:03:50.403 --> 00:03:54.100
I'm going to create ".content"
00:03:54.504 --> 00:03:05.800
I am going to tell you to have a width of 30% and an auto margin so that it is centered, I relate the
00:04:05.804 --> 00:04:13.700
stylesheet, link, css, folder and file.
00:04:14.004 --> 00:04:19.200
So I look, it would be this, I'm going to tell it to have the text aligned to the center
00:04:22.404 --> 00:04:28.400
this is how our form will be more or less, I will make it a little wider.
00:04:32.904 --> 00:04:41.200
So now we are going to start programming, I am going to create a folder to create the file from
00:04:41.204 --> 00:04:43.900
connection, I'm going to call it "config"
00:04:44.104 --> 00:04:50.000
Inside it I will create the connection file "connection.php"
00:04:53.105 --> 00:04:02.000
Then I will start creating the connection variables, that it connects to the localhost, that the user is "root"
00:05:06.505 --> 00:05:08.500
That the password
00:05:08.505 --> 00:05:20.900
In that case it does not have a password and the database I have created here is called "test" and
00:05:20.905 --> 00:05:29.600
it has a table called "admin", and "admin" has the user "alibaba" and the password "1234", which is the one we are going to use
00:05:29.905 --> 00:05:44.800
later, then the database is "test", and here I am going to create a connection variable that will be equal to "mysqli" and send it the connection parameters: host
00:05:46.905 --> 00:05:58.700
user, password and the database, we save and we go for this file.
00:05:58.906 --> 00:05:05.900
So here the first thing is the POST method, how we are going to send the data and who is going to execute
00:06:05.906 --> 00:06:09.400
the action that would be this same form "start.php"
00:06:09.506 --> 00:06:31.600
So here I am going to name the labels the name will be "txtuser" and the password name will be "txtpass" and the button will be called "btnin Start"
00:06:32.206 --> 00:06:39.400
Ready, then I'm going to create it here.
00:06:40.206 --> 00:06:52.500
I'm going to change the PHP language here, ready; then we are going to include the connection, it is in the "config" folder and the file is "connection.php"
00:06:52.506 --> 00:06:57.700
I will create create the variables that are
00:07:01.207 --> 00:07:10.800
POST ['txtuser'] and POST ['txtpass']
00:07:13.807 --> 00:07:27.100
Ready, then I will also create another variable for the button that I will call as it is called at the top "POST ['start btn']"
00:07:28.607 --> 00:07:40.000
So here we start with the programming, I'm going to tell you that if we click the button, if we click the start button
00:07:42.207 --> 00:07:43.300
What's going to happen ?
00:07:46.107 --> 00:07:55.600
We are going to check the database that if these fields exist, then I am going to tell you to select
00:07:58.908 --> 00:07:02.000
user and password
00:08:07.808 --> 00:08:09.900
from the table
00:08:14.808 --> 00:08:15.300
"admin"
00:08:21.408 --> 00:08:22.000
where
00:08:25.508 --> 00:08:26.400
the user
00:08:28.608 --> 00:08:32.800
It is the same as this user here
00:08:35.708 --> 00:08:40.600
and the password equals
00:08:44.208 --> 00:08:50.600
"pass", so let's run this, I'll make it bigger
00:08:53.709 --> 00:08:06.800
I'm going to create a variable and I'm going to call it execute, then I'm going to pass it the connection variable and we're going to execute this.
00:09:11.109 --> 00:09:15.300
Ready, here I am going to create a variable and I am going to call it "row"
00:09:18.209 --> 00:09:27.400
and I'm going to grill the query and then I will pass the "fetch_row" method to it, to fetch the number of columns there are
00:09:28.409 --> 00:09:29.100
In the table.
9. Login with Php7 Finish: In the table, then here I am going to ask that if the row in column zero would be the user, this is column 0 and this
00:00:14.400 --> 00:00:29.400
1 is the same as the "user" variable, which I am sending you and the row variable in the column
00:00:29.400 --> 00:00:32.700
1 which is the password is equal to
00:00:36.400 --> 00:00:42.300
"pass", the password that I am sending you, then
00:00:45.700 --> 00:00:47.400
to send it to
00:00:51.200 --> 00:00:59.000
I am going to create a file called "administrar.php", we are going to create it at once
00:01:01.901 --> 00:01:06.600
the file we are going to call "administrar.php"
00:01:06.701 --> 00:01:12.000
So here what you will have is
00:01:17.701 --> 00:01:18.600
say welcome.
00:01:22.601 --> 00:01:23.900
if not
00:01:27.101 --> 00:01:37.800
that you sent me a message, let's make it more pleasant here with Materialize / Dialogs
00:01:40.701 --> 00:01:41.500
I'm here
00:01:43.401 --> 00:01:44.800
But he texted me
00:01:48.601 --> 00:01:49.200
that says
00:01:55.302 --> 00:02:03.000
"Bad username or password", I'm going to put a class here to make it red.
00:02:10.402 --> 00:02:11.800
Done, let's try
00:02:15.102 --> 00:02:15.900
These errors here
00:02:15.902 --> 00:02:16.300
we already know
00:02:16.402 --> 00:02:18.700
We know how we control them.
00:02:18.702 --> 00:02:20.500
Let's put "error_reporting (0)"
00:02:21.102 --> 00:02:23.900
Zero.
00:02:24.202 --> 00:02:25.800
Here we are going to rehearse
00:02:29.502 --> 00:02:30.600
not me there
00:02:30.802 --> 00:02:32.400
sent the message.
00:02:32.702 --> 00:02:34.700
Let's check what we missed
00:02:39.602 --> 00:02:51.300
well here we needed to put quotes to the message and we are going to rehearse, now if it appears.
00:02:51.502 --> 00:02:52.500
Lets put.
00:02:52.702 --> 00:02:55.200
Let's look at the credentials.
00:02:55.402 --> 00:02:57.800
"alibaba" and "1234"
00:02:58.103 --> 00:03:00.400
We will put "alibaba".
00:03:00.803 --> 00:03:04.200
and "12", then let's give save
00:03:04.003 --> 00:03:06.700
Incorrect user or password.
00:03:06.803 --> 00:03:15.400
We are going to change the title of the button that would be "Enter"
00:03:15.503 --> 00:03:21.900
Then let's put "alibaba" and the correct password "1234!
00:03:22.903 --> 00:03:24.400
We are going to click to enter.
00:03:24.403 --> 00:03:28.600
and there it already shows us the message "Welcome"
00:03:28.903 --> 00:03:35.800
Here we have another small inconvenience that if we give it to enter without entering the credentials, it will enter
00:03:35.803 --> 00:03:39.300
directly, then here
00:03:41.103 --> 00:03:57.700
Well here what we are going to ask is if the fields are empty, if the user field is empty or the password is
00:03:57.804 --> 00:04:02.100
empty, send us a message saying
00:04:06.004 --> 00:04:07.600
"Enter in the fields"
00:04:11.204 --> 00:04:12.900
if they are not empty
00:04:15.304 --> 00:04:16.600
then now yes
00:04:19.404 --> 00:04:23.800
that they send us to the form.
00:04:23.804 --> 00:04:26.400
We are going to give him entry from the fields.
00:04:26.404 --> 00:04:28.200
I will fill one.
00:04:28.204 --> 00:04:36.800
If I put an incorrect password, then it will tell me "incorrect username or password"
00:04:36.804 --> 00:04:42.600
And if I fill in the fields correctly, it sends me to the following form.
00:04:46.404 --> 00:04:54.700
So here what we are going to create is a session variable, we are going to create a session variable
00:04:54.705 --> 00:05:02.600
We are going to start the session variable, with "session_start", we use this session variable
00:05:02.605 --> 00:05:11.500
both to close session and to know with which user we enter, then here we are going to initialize
00:05:11.705 --> 00:05:13.400
and here I am going to create a session variable
00:05:16.005 --> 00:05:25.100
I am going to call it "user" which will be the same as the user field I am entering
00:05:28.205 --> 00:05:31.000
I keep and manage the same.
00:05:34.105 --> 00:05:46.700
I'm going to put here in PHP, I'm going to initialize the session, and here I call that variable, then I'm going to put a print
00:05:48.905 --> 00:05:49.300
"threw out"
00:05:52.606 --> 00:06:00.100
"Welcome" and I put the session variable that I created.
00:06:05.806 --> 00:06:20.400
I save, I update I will enter "alibaba", "1234", I will enter, then here the message "Welcome alibaba" appears.
00:06:20.006 --> 00:06:29.600
So what we are going to do next is give our application a little security, I am going to create
00:06:29.606 --> 00:06:37.000
the exit button because if I enter here to administer here I could enter.
00:06:38.006 --> 00:06:44.800
Here the first thing we are going to put is "error_reporting (0), so that it does not show us the errors it has, in this case that
00:06:44.806 --> 00:06:50.400
They are controllable, so see that if I enter "administrar.php", I can see what is here
00:06:50.406 --> 00:06:51.800
If I had more information.
00:06:55.707 --> 00:07:04.700
So here we are going to create a button in the tag "form" with action "administrar.php"
00:07:04.807 --> 00:07:11.500
The POST method, and here I am going to create a button, I am going to take it as a reference from it.
00:07:17.307 --> 00:07:23.300
I'm going to call this button "exit"
00:07:26.107 --> 00:07:28.000
"btnsalir"
00:07:30.507 --> 00:07:36.100
I save, update and there is the button.
00:07:38.607 --> 00:07:40.600
I'm going to put the stylesheet.
00:07:46.007 --> 00:07:55.400
I save and update, then there is the button, it is not programmed yet it does nothing, so here we are going to program it-
00:07:57.008 --> 00:08:09.300
I'm going to create a variable and I'm going to call it exit, I'm going to relate it to the name that I put to the "btnsalir" button, so here I say
00:08:09.508 --> 00:08:14.100
If you click
00:08:14.108 --> 00:08:15.200
If you click
00:08:17.908 --> 00:08:27.200
to the exit button what is going to happen?, then first to destroy the session and second
00:08:27.508 --> 00:08:28.600
send me to
00:08:31.008 --> 00:08:36.600
the form start.php
00:08:37.908 --> 00:08:45.500
Here I will save, update, I will put "alibaba"
00:08:45.608 --> 00:08:56.100
"1234 ° and I'm going to click on exit, then I left there, it destroyed the session, but if I continue to enter here
00:08:57.308 --> 00:08:58.900
it will work for me.
00:08:59.209 --> 00:09:06.800
So here what I'm going to ask is if it's empty,
00:09:09.909 --> 00:09:19.100
the session variable, if the "user" variable is empty it means that we clicked the Exit button.
00:09:19.609 --> 00:09:24.600
If we clicked then let me get back
00:09:28.709 --> 00:09:34.500
to start, then I will save, update
00:09:34.809 --> 00:09:42.100
So I'm going to try to enter to administer, then we see that it does not let me enter because we are
00:09:42.109 --> 00:09:49.800
asking that if the user session variable is empty, it is because they have not logged in.
00:09:49.009 --> 00:09:54.300
Then I will do the full essay "alibaba", "1234"
00:09:54.510 --> 00:10:02.500
Enter, then there I am, if I let him out and try to enter this way he will no longer let me
00:10:02.510 --> 00:10:03.300
Enterokay.