PHP For Absolute Beginners | 6.5 Hour Course

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everybody my name is ram and welcome to my php course this course is full for absolute beginners the only prerequisite for this course is html in this course we're going to learn all the basic things php developer needs we're going to learn how to set up working environment how to work with variables loops how to write eval statements how to write functions how to work with dates file system how to work with sessions and cookies and many other minor things but more importantly we're going to build a product squad application and we're going to build that application three times first we're going to build like a very beginner would build and we basically don't pay attention how well we write the code so we will have code repetition and very unoptimal code but the main thing is to build that application which will be working and we're going to achieve that goal and we're going to also learn a lot of things by making our mistakes and then fixing these mistakes after this we're going to change our code and make it more optimal we're going to create reusable files reusable piece of code and then the second version will be much better than the previous one and while building this product squad application we're going to learn how to validate the form how to work with file system how to upload files how to work with mysql database after this we're gonna learn modern tools like namespaces autoloading and composer and using that tools we're gonna build a custom mini mvc framework yes we're going to have controllers models and views and based on that minimizing framework we're going to rebuild the product squad application third time but in this case the approach how we build will be completely different and when we compare the latest version of that product squared application to the previous one we're going to understand how much difference is there and how well you can write code in php if you don't know me i'm the code holy can i run my own youtube channel where i upload videos about web development coding tutorials and challenges all the source code which i write in this video is available on my github and you can find the link in the video description before i start i want to say huge thanks to brad traversy for two main reasons inspiring me in many many things and having me on his channel when i started my own youtube channel two years ago i couldn't even dream about creating content for traversing media but today i'm here and i'm probably the happiest man if you find that video useful hit the like button if you're new to traverse media hit the subscribe and the bell notification button and let's start first of all let's have a look at the course plan it's going to be several hours course so we need some plain so first of all i'm going to explain what is php and why we should learn it then we're going to download and set up working environment we're going to write hello world we're going to learn after that how to write comments how to declare variables and what data types exist in php after that we're going to learn some numbers and string functions how to declare numbers how to declare strings and a couple of functions working with that then we're gonna learn how to work with arrays after that we're gonna write some conditionals and see how we can declare conditionals in php after that we're gonna go to loops functions including files in php to include one file into another after that we're gonna see how to work with file system how to create directories delete directories how to create and write inside the files after that we're gonna have a look at the object oriented programming in php it's not going to be a full course about object oriented programming but it will be good starting point if you are new to object-oriented programming so after that we're going to have a look at the c url serial is absolutely necessary tool for every developer to communicate to other resources through the internet so we're gonna learn this after this we're gonna have a project so that's gonna be several hours project it's not gonna be simple thing so we're going to set up a product crud application so first of all we're going to create that crowd application with the easiest possible way just like the any beginner would do so we're going to make some mistakes we're going to write an optimal code we're gonna have code repetitions and so on but then we're gonna rewrite our code and make it even better and finally when we learn namespaces and autoloading and composer in this course we're going to come up to our custom routing and we're going to create a mini mvc framework and rewrite our product squad application based on that framework and we can see how much difference is in the code how structured the code can be when you come up to such structure like the mvc for example with custom routing and so on so basically we're going to have three versions of that product crowd application bit version where will be a lot of code duplications and things like that then the better version improved one and the good one which will be based on that custom routing and composer okay during this project we're going to learn how to validate the forms how to upload files and more importantly how to work with mysql so and finally we're going to have a look at the sessions and cookies so how we're going to set the cookies sessions and what are in general purpose of sessions and cookies okay let's start and before we start actually we need to have a look at the prerequisites so the only required prerequisite is html so you need to have a decent knowledge of html to take the course basic knowledge of programming is kind of optional if you know how to write loop how to write an if statement that will be good it will help you a lot but if you don't know i'm going to explain these things also in css it's kind of optional as well so if you know html probably you have some experience with css as well but i'm not going to write much css actually in this course so it will be more focused on html and php okay let's start with the main question what is php php is an open source general purpose scripting language it is a recursive acronym so the first p stands for php itself h stands for hypertext ndp stands for preprocessor it's a server-side scripting language as i mentioned and it's best suited for web development so it's very easy it can be embedded into html and its interpreted language so let's have a look at the reasons why we need to learn php it's multi-purpose scripting language meaning that we can build simple websites on php as well as some complex ones some crm systems some e-commerce systems rest apis we can even use php for building some image video and audio manipulation software so it works fine with almost all databases including known relational databases as well it's very easy to set up very easy to learn it has a very large community and on php there is written a lot of very popular cmscs and frameworks like the wordpress for example which is written on php is the most popular cms in the world out there so there are many other you know popular cms's on php such as magento drupal open card some of them are e-commerce systems some of them them are cms's some of them are both at the same time php frameworks so laravel itself is the most popular backend framework among all other backend frameworks out there even if it's django or node.js frameworks so laravel dominates in terms of number of github stars so it's very very popular one and very very well written one so there are many other popular frameworks on php like symphony codeigniter e2 framework all of them are absolutely great and one last but not the least reason why you might need to learn php why you should learn is that there is quite high demand on job market regarding php okay so we should also mention that php is not probably the best language for uh building real-time chat applications and artificial intelligence and machine learning so probably node.js will be the best one for building some real-time applications like chat for example and python would be probably the best one not probably but it's the best one out there number one language for artificial intelligence and machine learning applications that's all about slides now let's open fresh installed windows 10 and set up working environment there so here i have fresh new installed windows 10. i just installed google chrome nothing else and we need to download necessary software and installed on our operating system for this course i'm going to use phpstorm for code editing so i really recommend phpstorm but the only disadvantage of the php storm is that it's not free you have to pay for it as a free solution i suggest visual studio code but i'm going to download both of them set up both of them so that you know i don't know which one you prefer so that you have a guide for both of them so first of all just type phpstorm and open the download link and click on that download button for your operating system i have already that downloaded so i'm not going to click that button so then let's open vs code go to the download section and download for your operating system so just click that button if you are a windows user and then we need to download xampp what is xampp xm is a package which contains apache mysql php and couple of other things we only need apache mysql and php in this course so we have to download that let's download the latest version which includes php 7.4 right here so i'm i'm gonna click download button and it will download the xampp so i also have that downloaded so i'm not going to click actually but you have to download for your operating system down below we have the uh for linux exam for linux and we also have for mac os so just download for your os right here i have the downloaded exam php store in vs code and let's go ahead and install xampp first so xampp as i mentioned is a package that contains apache mysql and php apache is a web server which is necessary to process php files and send output to the browser we have to answer a couple of things right here on this screen so i'm gonna untick tomcat mercury filezilla webalizer and fake send mail i'm gonna leave all the other things phpmyadmin is a web-based client to interact with mysql and we will need this later in this course so i'm going to click next installing the default location untick the checkbox next next and that's it so let's install now phpstorm so the installation process is very simple we just need to double click and follow the wizard so right here we have it so next next right here i'm going to take the 64-bit launcher i'm going to add open folders project which will add in the windows context menu and basically i'm going to leave everything else right here click the next install and let's also install visual studio code so double click on that so i accept next next right here i'm going to create the desktop icon tick that checkboxes and tick that one as well and you have it okay vs code is very lightweight open source code editor you probably know about that and it's its installation process will be very fast and as a choice of editor i really encourage you to use php store if you do have enough money to purchase that it's very intelligent ide very uh like clever one and very complex and flexible as for the free choice vs code is quite good uh so we can use vs code just you have to install a couple of extensions to make it good enough to work in vs code so i'm going to show you as well which extensions one extension basically which covers most of the things is necessary to install in vs code so let's wait until the installation is done and then we can continue so here vs code is already installed let's click the finish that opens up the vs code and we have to install a couple of extensions so right here let's go to the extensions and i'm going to search for php intellifence okay we need that extension php intellifence which has 2.2 million downloads that is extension which gives you most of the features you need in php like the autocompletion and code formatting and so on so just click the install button and it's going to be installed so i'm just going to work in vs code so i'm just going to close that and wait until the php storm is done so it's done right here i'm going to click the run phpstorm click the finish and configure that the example is also almost finished so here both of them finish the installation so let's first open phpstorm i'm just going to import anything click ok so i'm going to choose the tarquilla theme and skip remaining and set defaults so i'm going to evaluate this for free which is 30 day free trial so just click evaluate i do have an educational license which generally i use but i'm just going to supply it right here okay and here we have this is the php store so i'm going to close this right now and open later when we download the source code files on which we need to work and let's open let's focus on the example installation so this is actually done and finished so i'm gonna start the control panel right here and here we have so we have couple of services right here but apache and mysql are the only services which have that button start button enabled so if i just click the start button this will start the apache service running on port 80 and 443 both of the ports are necessary sometimes there are problems about these ports and you just if you have that problem you just need to have a look at the log right here probably it will write some red text that the it couldn't start and then you need to google find out it can be uh it can happen because of multiple reasons so there's no single uh answer on that okay and let's start mysql as well okay and the mysql starts on port 3306 now let's open browser and in the browser we're going to test if the installation of apache is running so i'm going to type localhost in the browser hit the enter and if we see welcome to xampp page this is all what we need so we have apache installed successfully and it can process php files let's also check if mysql is running so i'm going to type localhost slash phpmyadmin hit the enter and we should be able to see the web-based client application to interact with mysql so here we have it now we need to make php comment available from command prompt so if we just open right now comment prompt and type there php-v this prints php is not recognized as an internal or external comment okay to make this working we need to open the xampp installation folder go to the php folder and this is the folder basically which contains the php executable file so if we scroll down right here we see php excel okay so we need to copy the following path and go to this pc right click in properties go to advanced system settings environment variables click on path and edit and right here we need to add that php executable path okay i'm going to paste this c drive xm php and click ok and right here we need to also click ok just the window is behind the taskbar so i'm gonna click that using keyboard okay click ok right here close that and let's just open right now command prompt and if we type php v this prints php 7.4 so we will need that php comment to be available and we're going to use that later in this course i'm going to also show you how you can make your exam services apache and mysql services run as services okay so let's go to the exam installation again scroll down and find exam control access so right now i'm gonna close that actually i'm gonna stop this both of them and close the control panel and i'm going to open the xom control using right click and run as administrator okay we have to agree on this and now it shows that red x is next to apache in mysql okay because we run this as an administrator we have possibility to enable the services and just click on them okay and the service is basically basically installed and if we go to the config and tick the checkboxes right now apache in mysql and click save so this basically means that whenever we restart our machine apache and mysql will be automatically started okay so now i can start them back just we had it before and here we have it now we need to download the source files which we need to work on so let's go to the following link github.com the codeholic slash php crash course 2020 so that is the repository which we have to download on the master branch we have the uh initial files the uh which we need to download and follow and if you want to see the final files you can found these in the final version right here so i'm going to click that code button and download zip right here so i'm going to open that and i'm going to actually move these in a specific folder so let's go to the c drive xampp where our example is installed and htdocs okay and i'm gonna paste this right here so this htdocs folder corresponds to localhost in the browser so let's type localhost right here once again and the local host basically corresponds to the hd docs folder so i'm going to extract this right now right here and i'm going to also just close this i'm going to also rename this and remove that master okay open that and there's nested one more nesting level so i'm gonna basically take out everything and put it right here and delete that master empty folder now if i type php crash course 2020 in the browser next to the localhost right here so let's do this we will see all the files which are inside that php crash course 2020 okay these are all the files and from now on if we open one of the php files from here this will be processed by apache and it will give us output in the browser okay so now let's open that folder in the using the phpstorm and start writing hello world so open folders php store let's wait a couple of seconds i'm going to actually minimize this let's move this on the right side i can't move this on the right side for some reason so phpstorm compared to vs code is a little bit heavier so if you don't have very good working machine the vs code will probably be better in terms of performance if you have a good machine good pc then the difference between the vs code and the php storm in terms of performance is not that big okay so i'm running this in a virtual box so that's why it's working slightly slow let's open this and you have it so on the right side we have the browser on the left side we have the php storm with all the source files we need okay now let's start introducing syntax of php okay let's write hello world in php first of all you probably noticed that my php storm design is slightly different from yours that's because i have just installed theme okay let's open syntax html on the left side in the php store and we need to open the following file in the browser as well right here which prints hello world so in order to make the php working and inject and embed in our html file we have to first change the extension from html into php so when i do that and open that change the file in the browser the output is the same so html is displayed just like it was displaying before so that's because php is embedded inside the html and in php files you can actually have only html and nothing else but you change the extension and it gives you possibility to write php tags right here okay so i'm going to write a php tag less than question mark php is the php opening tag and question mark and greater than is php closing tag in between those tags now we can write php comments for example let's print hello world from php echo hello world and semicolon at the end i save this refresh in the browser and it prints hello world if we have a look in the page source we don't see these php tags we just see hello world that's because apache processes these php tags evaluates the output and sends that output to the browser we can have as many statements inside these php tags as we want for example i can write hello world and and php save that semicolon refresh and here we see hello world and php so we can also have multiple php tags inside html for example just like this one so echo hello from another tag okay semicolon refresh and here we see just because we are just outputting these things we see them on a single line however we can output also html tags so right here i'm going to write echo br tag so that will just output beer tag and now we see this hello from another tag on a new line and if we have a look in the page source we see right here beer tag using this approach we have possibility to output basically any tag for example button click me just like this one save refresh and here we see that button okay let's move on and see how we can have comments how we can declare comments in php okay in php there are three ways to declare comments so one comment one way let's say we have basically two ways to declare single line comments in one way to declare multi-line comment one way to declare single line comment is double slash so in this single line comment and that's common for almost all programming mainstream programming languages like python maybe in python i don't remember exactly in javascript for example so another single line comment is using hashtag single line and the multiline comment is slash asterisk and then asterisk and slash and in between we can write like multi line comment move on the next line right here we can move this down also multi another line and so on okay so these are multi-line comments okay let's go ahead and see how we can declare variables in php so i'm going to open the variables file and i'm going to open that variables file in browser as well so in general what is a variable variable is the pretty much the same in php as in any programming language it is a container that stores some values okay in php there the variables basically don't have types so php is loosely typed language and whenever you declare variable you don't specify the type and the variables have dynamic types which change the type based on the value whatever you assign to it okay so in order to declare a variable you need to use the dollar sign dollar sign and then the variable name variable must start with the letter and after that or underscore and after that it can contain like digits as well so for example name would be a valid name of the variable name equals zura for example age equals to 28 and semicolon so i just declared two variables one is name second is h and i don't use any um any types for that so let me remove it um i just wanted to show it to you something so the name right now has a dynamically taken type based on the value and the name has type of string age dynamically took a type of that value and it's an integer so in php there are several ways several types so here are the types in php so string integer float boolean null array object and resource so now i'm going to declare five variables with different types right here so name age is male equals true hate equals 1.85 and salary equals null okay so the first variable name is string age is integer ismail is boolean hate is float or double so it can also be double and the salary is basically now okay okay what to do if i want to print the variable so i just use the echo statement which prints something and then use the name so a code name save that refresh in the browser and we see zero right here okay if i want to print another variable echo age for example save that and i see them next to each other so basically because we don't have any space between these two echo statements they are next to each other i'm going to use the beer statements this does just uh this just means concatenation so right here i'm gonna use the dot sign to concatenate name and beer tag and print both of them at the same time and right here i see them on the next line so i will do that pr a lot to just show a couple of things on the different lines okay so i'm going to basically print all variables right here save that and refresh excuse me so i i copied something wrong from my second screen so right here okay and the refresh in the browser and here we have all the output but look at this ismail is true but on the browser it prints one which basically means that whenever boolean is converted into a string and boolean is converted into a string when we try to print that boolean variable so whenever it's converted into string the true is converted into one and false is converted into an empty string okay so if i change that ismail into false save and refresh it in browser i don't see any output okay because it's converted into an empty string the salary is null and null is converted into an empty string as well when we try to print it on the screen okay so let's uh print the type of these variables for this there's a special function git type so i just type git type give it a name and refresh in the browser and we see that it has a type of string okay so for age it will be integer and so on so let's see all of them so i'm going to paste this right here get type for name age ismail hate and salary refresh and we see all the different types and the height is double as i mentioned it can be float or it can be double they are basically the same okay what if i want to print the whole variable and that's very useful for debugging purposes to see what the variable contains so i'm going to use var dump a function for that specify the variable and refresh in the browser and right here we see that this variable is a string with the length of 4 and this is the variable okay so this vardaman function is super useful when working with large variables like the arrays or the objects so it prints out all the information you need okay let's print h as well and is male and salary and hate okay refresh and right here we see this is the name this is the age this is the ismail which is boolean true the salary is now and the height is float 1.85 okay now i'm going to change the name variable into false we know that the name variable was zura it was a string after that if i try to print the type of the name variable it preads boolean okay let me show you a couple of useful functions when working with variables so for example if i want to check a specific variable is a string or not i will use ease string and specify the variable name and it will evaluate into true or false in this case because we change the name variable and assign false to it this will evaluate into false so the name is not string so we have a couple of other variables so i'm going to paste this right here we have is integer age in our case age is definitely integer so this will evolute into true is boolean is double we have a couple of others like is array and so on okay so if i want to check if the variable is declared or not i'm going to use is set function inside the essays function i will specify the variable name and this will check if the variable is declared in the current scope or not and evaluate into true or false in this case this will evaluate into true if i try to call easy set on another variable like address for example which is not declared in the current scope this will evaluate into false okay okay let's talk about constants so in php constant basically is a variable whenever you assign something you cannot actually change that it's not actually in a variable it's a constant okay in php we have to use function define to define a constant you have to specify the constant name for example pi and the constant value for example 3.14 okay and the value basically can be number it can be boolean it can be string as well and in latest versions it can even be arrays okay how to print out the constant so i'm going to use just pi without taller sign so this is how we access constants in php so i just print pi with beer tag refresh and right here we see 3.14 there are a couple of other built-in constants in php which you can just use so for example sort sort ask and which just corresponds to some number and that's very often used for sort ascending okay and another variable another constant excuse me is i want to print this php int max okay we just prints the maximum number the integer can have in php so refresh in the browser and right here i see the four for sort max constant and the integer max number is just this okay that's all about variables let's move on and talk about numbers so i'm going to open a numbers php on the left side and numbers php on the right side as well and let's start okay so we know how to declare variables so i'm going to write away the clear variable like a equals 5 b equals 4 and c equals 1.2 okay you can probably see that the a and b are integers and c is float okay now i'm doing arithmetic operations on that numbers so for example i'm going to print out immediately a plus b so we should print out 9 right so we can have a look 9. so we can actually have multiple arithmetic operations combined like a plus b and plus c and that will give us 10.2 so if i change that plus into multiplication then it's obvious that first the multiplication is done and then the addition will happen so we will get this 9.8 okay if i put this a plus b in a parenthesis first the addition will happen and then the multiplication and we will get the different answer okay so basically all kind of arithmetic operations uh can be done in php like the addition subtraction so i'm going to quickly copy and paste all these things okay right here okay and the person signed basically means a reminder so the other things i think are very clear multiplication division and the module sign means the remainder so whenever i a is divided on b what's going to be the reminder okay and in our case the reminder will be just one okay right here okay so if i just want to add a to b but save that information into back a i will do just like this right a equals a plus b but in php uh and in other programming languages as well we can use assignment with math operators okay what this does actually mean is that we can use plus equals b a plus equals b means the exact same thing a equals a plus b and after that i'm going to print out immediately a for example the a will be changed okay so and here we see that the a is now nine okay we can do all uh basically this for all types so i'm going to copy and paste this and uncomment the code and right here we see that we can do the same thing just i'm going to comment out one and leave the others so for example on subtraction we should see that a equals one refresh and here we have it okay on multiplication a will become 20 and so on i'm not going to basically explore all of them just to save some time okay so what about increment operator so increment operator is plus plus operator which means that to increase the value of the a by one okay there exists two types of increment operator plus plus a plus plus and plus plus a okay what are the difference so whenever you use the variable a a plus plus with some other operation like the print for example so when i use that a plus plus with echo first the value of the a is taken and printed and then a is increased by one okay however if i use that plus plus a with echo first the value of a is increased and then it's print out so right here on the line 23 whenever we execute this we should see that a value is 5 right so we should see five printed okay but the value will be increased by one and it will it will become six after that on the line 24 the value of a is increased and it will become seven and then it is print out so we should see basically five on that line and seven on that line save refresh and right here we see 57 basically which means that this is the five this is the seven so we can put right here pr tag and here we have okay so in the same way we have decrement operator so a co a minus minus with br and a co minus minus a okay just like this and we should see the vice versa like the seven and the five let me put b over here as well okay perfect there are a couple of functions to check if the variable is number so for that we have is float for example and i'm going to specify for example 1.25 and that will evaluate into true that 1.25 is actually float we have also is double which basically does the same as is float so that will finally give us also true we have is integer uh is integer and is int and they are also the same okay i'm going to specify 5 for example which will evaluate into true we have also is is numeric which is the most interesting one so inside is numeric i can specify a string value for example 3 points uh 45 let's say and this will evaluate into true because it understands what's the actual value of that string and that prints out true however if i put some string inside that for example 3g point 45 this will evaluate into full false because that is not numeric value anymore okay i hope this makes sense so let's see how we can convert a string value into an integer or float so if i have a str number right here variable which contains a string value for example 12.34 and i want to convert that into a float number okay number equals i'm going to use parenthesis right here float inside the parentheses parenthesis and the ester number okay so that means that take this string number and cast it on the float so finally this number will be a float and we can see this by dumping that whole variable number right here refresh and right here we see 12.34 if i want to convert this into an integer so we have to type an integer and that will be casted into 12 as an integer so we have other ways like we can use float valve as a function and specify this string number and that will be converted into string or we can use int val and specify the number and this will be converted into an integer okay so let's see couple of functions when working with numbers so i'm going to copy and paste these numbers and explain them so just to save some time okay so right here i have a string written the function name and the argument given to that function and this is concatenated to actual function execution okay then we have some output so if we have a look in the browser i'm going to put br right here to have a new space new line okay and here we have so this basically means that the uh result of that function execution is 15. so let's have a look at these functions the abs function takes number and returns the absolute value of that function so for negative numbers it will be still 15 and we can have a look right here the pole takes two arguments the first is the base and the second argument is the exponential so 2 in power 3 means 8 the sqrt function takes the square root from that value and it's 16. max basically takes the maximum number of given ones and we can specify even multiple numbers right here two nine and three and this will print out max will print out nine right here okay it just prints here two comma three because i have written two comma three as a string right here okay say refresh right here so the minimum takes the minimum among given one the round basically rounds the number in a normal mathematician way and this will be 2 and we can see right here round of 2.6 will be 3 obviously and we have floor and sale functions as well floor means round down sale means round up so even if you floor 2.6 this will be always 2 and the sale of 2.4 will always be 3. okay so let's see number formatting how we can format numbers this is very useful uh function which is used in practice a lot so let's say that i have a number um like one two three four five six seven eight nine uh point one two three four five just like this okay large number and i want to format this in a in a way that we have for example um spaces in between these thousands and we don't display the like anything after the two digits after the uh decimal separator and we can have a for example comma so i want to format my number like this okay for example so let's use a function which is called a number format so echo number format we have to specify the number then we have to specify how many digits i want to be there after decimal separator and i'm going to specify two okay and this will basically strip everything after that one two right here okay so after this we specify what i want to be thousand separator and i'm going to specify right here no actually the third argument is let's have a look decimal point is the third argument and thousand separator is the fourth argument okay so for decimal i'm going to specify comma and 4000 separator i'm going to specify space okay let's save this and refresh in the browser and down below we see the following thing i haven't specified space right here refresh and here we see so we see spaces in between this thousand separator and we see comma as a decimal separator so i can change that comma and put a dot and i can put comma as a thousand separator so here we have a different formatted number okay so here i have a link which gives you uh all the functions math functions working with numbers i really encourage you to check out that link that's the official php documentation and just take all the check out the functions and see how they work so that you know what possibilities you have in php when working with numbers okay there are many others we haven't covered okay let's move on and talk about strings okay i'm going to open strings.php close the others and i'm going to open also strings.php on the right side right here okay perfect so let's start and create a very simple string for example string equals hello zura for example okay and i'm going to declare same type of type of string with double quotations right here okay and both of them basically are doing at the moment the same so i can print string and i can print string two okay and we can see that they print the exact same thing however what's the difference between the single quotations and double quotations so so if i take out that zura and save in a variable name for example okay and i want to concatenate that hello with zura so i just need to do hello concatenation in the name right so dots is basically used for concatenation okay right here i'm going to write name okay and it will give us the same thing however if that string is very long and you want that name in between you have to do um like not in a very friendly way like hero hello zura for example dot um hello for example let's write hello i am zura i am the name and i am 28 for example okay so you have to do the concatenation just like this however if you have all this string the following thing in double quotations and let's do it like this hello i am i can directly put that dollar name in the double quotation okay so let's have a look so they are doing the same thing at the moment however if i put that dollar name on the first line in that single quotation string it will be printed just dollar name if you have that name written in a double quotation in this case it will evaluate that as a variable and print out its value and here we see i im0 okay so we have already seen how we can concatenate string so i'm just going to write a very simple example hello concatenation with world okay and we can even specify concatenation as many times as we want and php okay let's put beer here as well refresh and here we see hello world and php okay now i'm going to create a variable called string with some value basically i'm going to copy the following thing and let's explore a couple of functions when working with strings so here on line 13 i have a variable hello world with spaces next to each other and then i'm just calling couple of functions on that string okay and i have numered them so that we can easily identify which function is which one okay and str length basically prints the length of the string okay and we can have a look right here the length of the string is 21. trim removes white spaces from the beginning of that string and from the end of that string okay l trim removes white spaces from the left side it means left trim but it leaves that white space is on the right side r trim removes white spaces from the right side but leaves them on the left side okay and on the right side basically this stream um l3 and rtream basically they are printed out pretty much the same but that's because uh html just ignores the white spaces okay so if we have a look in the page source we can see that this is the result of the tree this is the result of the l trim okay and we have white spaces on the right side and this is the result of the r trim which leaves the white spaces on the left side okay so str word count just print outs the number of words in that string and in this case we have two scrive just reverses that string and we have the hello world in a reverse order str2 upper converts every letters into an upper case str2 lower converts every letters in lowercase we have uke first as well which converts the first letter into uppercase which means that upper case first so only h will be converted into an upper case and right here we see h in uppercase we have lc first which converts the first letter into lowercase okay we have also uc words which means uppercase words and only h and w are converted into an uppercase which basically converts the first letters of every word okay so if i just print hello world and php right here in the refresh we see a and php also in uppercase okay we have sdr pulse which searches for world inside that string and right now on for the number 12 it actually doesn't print anything so that's because our string doesn't contain world with lowercase w okay we have world with lower case right here but uppercase in the uh html in the initial string sorry okay so actually if i change the w into lowercase it will print out 10 right here okay but if i want to ignore the case there's a special function for that is tr i pose okay which basically this i additional i means for ignore case okay in this case it will search for world occurrence that pop-up basically is the php store and pop-up which when you mouse over on that function it gives you the documentation of that function okay if you're a vs code user you probably won't see that okay so this stri pose in this case will print uh 10 okay so we have substr which substitute just like this which basically takes up takes out the substring of the string okay i want to take out the substring from that string variable from position 8 until the end of the string and this is the substring okay we can have a look in the page source for number 14 and we can see that it takes out all the way to the end including white spaces however if i want to take out not the whole whole length length but several characters for example six only we can see right here it only takes out the six characters okay the third argument basically indicates the length of that substring there is also a function str replace which searches for word world in that string and replaces with php inside that string okay so the first argument to search something second argument is to replace that and the third argument is where to search and replace okay and in our case we um refresh it and we see hello world hello php right here but if i change the w into lowercase okay lowercase world does not exist in that string right here so it won't search that and won't replace so right here we see that hello world the initial string basically whatever was there okay however there is another function stri replace which basically ignores the case so it searches for that world ignoring the case and replaces it with php inside that string so finally this gives hello php okay that's basically a short list of the functions that is in php in php there are a lot of a lot of functions so i really encourage you to check out that and let's see now a long text basically multi-line text with some line breaks so here i have a text hello uh my name is zura i'm 27 i love my daughter and i want to display this text exactly as it is with these line breaks okay so if i just print that long text so because html is ignoring that white spaces we will see that thing so basically i'm going to comment out everything above okay oops save that refresh and here we see so hello my name is and that's basically all of them in a single line okay in the page source they are on different lines but you know why because this is the html how the html works so if i want to reserve that line breaks there is a special function in our nl 2br which means that newline to br and it creates br tags whenever it finds that new line okay so if i just print this i see that this is exactly as i expect as i want okay so and in the page source it creates that br tags whenever there it finds that new line okay so i'm going to now paste another multi-line text which has also tags right there okay this is the tag this is the text so it pulls out something so if i just again print out that information that long text okay it prints on a single line with the bold zura and bold 27. okay so if i want to reserve that new lines i have to use an l2br okay and but sometimes i also want to uh reserve these tags and display them as a tags not as a bold okay so let's just print all of them okay so i'm going to copy and paste something okay right here and let's have a look so i just print long text then print nl to br and then i use a new function which is called html entities which reserves these b tags and displays them as tags not as a bold let's have a look so i'm going to comment out these above two okay and here we have three output so this is the first one displayed as expected this is the second one displayed as expected but i want this to be displayed as it is written in the code okay okay right here we have the b tags but i want also these spaces to be reserved so we have to use right here nl to br not to but this should be four and l2br and html entities together okay nl2br giving the html entities and that finally gives me what i want what i have written in my code okay with the tags and with the correct line breaks if we have a look in the page source we see that these entities how they are converted into an entities that greater than and less than symbols okay that's why you need to have basic knowledge of html to know what are in general html entities okay so that's basically um all i wanted okay let me show you also how you can decode that html entities okay so if you have converted if you have these entities so i'm gonna take out these uh probably okay and just right here uh type html entity the code okay give that string and it will decode that and print the decoded one so right here we see that sura okay in the uh source code we see that the b text surround the b text okay so that is html entities code so i'm going to open this link right here we have a lot of string functions as always i encourage you to check out that documentation link read that functions at least once to understand what is possible in php okay okay let's move on and talk about arrays so i'm going to open right here arrays okay open that on the right side as well okay and let's start okay what are in general areas so arrays is a arrays are variables which can contain more than values so it contains a series a list of values okay how to declare a raising php so we declare a variable for example fruits which equals square brackets and inside the square breakers we put the values okay this is pretty much similar the same as it is in javascript for example if you're familiar with javascript but we have another option to declare areas like array inside the parenthesis okay that's an old old-fashioned approach but you will meet this very often because it is used heavily but i'm going to declare with square brackets okay so i'm going to declare three elements inside that array banana apple and orange okay so sometimes i declare with double quotations sometimes single ones so i don't have a like a preferred choice okay if i want to use a variable inside the single quotations i generally inside that string i will use the double quotations okay so let's print the whole variable and i'm going to use a var dump for that specify the fruits and refresh in the browser and we see that's not very user-friendly and readable text okay if we have a look in the page source we see that in a nicer way and it is readable actually so this indicates that this is an array of three elements this is the uh first element string with sixth length this is the second element with the index one and this is the last element okay so arrays in php start with index zero so that's why this is the zeroth element this is the first element this is the second element okay but if i want to this to be readable and visible uh nicely in the browser so i generally use the pre-tags okay so pre-opening tag and right here i use a pre-closing tag so i save refresh this and this is how i see and i also have a shortcut right here dump specify the fruits and this is as easy okay so let's see how we can access elements by index so if i want to print the element at index 1 for example i will use fruits 8 1 with square brackets notation and just print that okay save refresh right here we see this apple if i want to if i try to access element at position three i will get a warning because there is no element at position three okay so if i want to set element by index i can do in the same way for for example fruits at position zero i'm going to change that into peach for example save and then let's just print the whole new array fruits and we saved the first one it is not banana anymore it is now pitch okay so if i want to check if specific element exists in um area yet specific index if there isn't something in the array i'm going to write fruits at position 2 for example and put this in the easy set function okay we have seen that is set when working with variables so this finally evaluates into true that there is an element at position 2. if i specify right here 3 there is no element at position 3 so this will evaluate into false so if i want to append element at the end of that array i'm going to use a square brackets notation and add right here banana for example okay and we can dump the whole fruits once again and see that and down below we have banana as the last element at position three so whenever you append it takes the next uh next index okay so if we want to print the whole length of that array i'm going to use a count function and specify that fruits this will finally give us length of four because we have four elements okay so we see how we can append with the square brackets notation but there exists a special functions for that as well so for example array underscore push we specify the array and we specify the variable the string the value i want to append and it can be even not a string but it can be number so in php areas basically can have a different type of failures there okay you can have a mix of numbers and strings and booleans and even sub arrays and everything okay so i'm going to specify right here just full okay i want to append the full in the fruits area and we can dump right now the whole fruits area and we can see down below that we see a full right here if i want to a remove element from the end of the array i'm going to use a function array pop okay so i specify the fruits this will remove the last element which is in this case full and return that for so we can print that immediately but it will also modify this original array so if i dump that original array we won't see full anymore inside that area okay so refresh it right here i see foo which is taken out and printed but we don't see foo anymore inside it area so if i want to append not append but insert the element at the beginning of the array i have to use array and shift okay i specify the array and i'm going to specify bar for example so i want to put bar at the beginning of that array and let's just print the whole fruits refresh it and right here i see bar as a first element of that array if i want to remove that element the first one from the array i'm going to use array shift specify the fruits that will take it out and let's just print and the fruits will be changed so i'm not going to print this so it's obviously clear so if i have a string for example and um that string contains a couple of fruits for example banana coma apple comma and peach and i want to convert this into an array i have to use function explode okay i'm going to specify the delimiter in this case they are like delimited by comma and i'm going to specify the string and that will create an array and return that array so if i just dump the whole array and refresh right here i see this three elements array okay okay let's see the vice versa operation so if i have a fruits array which actually is described and i want to combine them with some separator i can use an implode function okay i'm going to specify the glue using which i want to implode them and i can use comma or n symbol okay and then specify the array and that finally creates a string combines them with that's glue and save and refresh and we see right here peach apple orange and banana of our original fruits area combine them as a string okay if i want to check if specific element exists in array or not i'm going to use a function in underscore array first we specify the element we're looking for for example apple i want to check if apple is inside that array or not and then we specify the array and if we put this in the var dump statement this will return true or false and in this case because we have apple in our original fruits area this prints true if i check if mango exists inside that fruits refresh it we don't see this returns false if i want to search for an element index note just check if the element is in the array but also search for that index i'm going to use a function array search again we specify right here an element for example mango in that fruits array and that finally returns the index but if the element doesn't exist in this case mango doesn't exist this still return false however if it finds that element apple for example it returns the index of that apple okay so if i have two areas and i want to merge them into single one so for example i'm going to create a vegetables array and i'm going to put right here potato for example and cucumber okay and i want to merge these fruits and vegetables into single one so i have to use a function array underscore merge and i'm going to specify first array and secondary the ordering basically matters because in the final merged array they will be in the same order so fruits first and then vegetables and that finally will return a new array which i can assign to a variable or i can just print just like this one refresh and right here i see a new array with element six peach apple orange banana potato and cucumber okay in php 7.4 which is right now at the moment of recording this the latest version uh in several months we're gonna expect uh php 8.0 in november it will be released but at the moment php 7.4 is the latest one and there is a better and better way to merge two arrays okay new notation okay which is called uh spread operator okay so i'm going to dump all these things so let me put far dump right here and i'm dumping new array and three dot notation and specify fruits comma three dot notation and specify vegetables okay right here my php storm puts in red underline it tells me that spread operators in areas are available in php 7.4 only so that happens because my php storm does not know what what language level i'm using so it actually internally has its own language level but it cannot understand that i'm using php 7.4 so i'm going to go to the file and settings if you're using php store and right here if we go into languages and frameworks go to php right here we see php language level set too so it is set to 5.6 okay i can change that into 7.4 and it will understand and it won't give me any errors okay so i'm gonna hit ok and the errors basically disappear or i can do this in a shorthand way like set this back to five point 5.6 and right here it gives me also this link switch to php 7.4 language level i'm going to hit ok and the error basically disappears okay so if i want to uh sort the areas basically i have a function for that sort i'm going to specify fruits and this will sort the arrays and return them just modify the original array okay in the in the correct order so if i just print fruits right now this will finally give me syntax error right here semicolon is missing refresh and right here down below we have that apple banana orange and peach so if i print that fruits area before sorting and after sorting so this is before sorting we see how it changes okay so we if we want to sort that in a reverse order we have to use our sort okay reverse sort and right here we see it in a reverse order okay let's talk about associative areas okay what is an associative area associative area is key value peers okay and it's very heavily used in php so i'm going to create right here a person variable which is an associative array i'm going to comment out everything at the top okay just like this one and let's create an associative array of a person name is for example bread surname is for example traversie and age is 30 and hobbies is tennis and i don't know video games okay here we have the person associative area okay if i just dump the whole person print that so i can see that this is an array of four elements the name corresponds to string of four bread and so on so we have basically everything so this bar dump basically prints out everything by the way there exists a second function for printing areas which is called print underscore r many people prefer this printer i generally use var dump but you should also know about that so this is how the array will be printed using print r okay so i'm going to return this back into var dump so now let's say that i want to access to the name of that person and print out the name so i'm going to use person square briquettes name and this will finally print out the name of that person if i try to access some non-existing key for example address it will give me warning notice that undefined index address for that person which is pretty logical so if i want to set something for example i want to set the person's channel and i'm going to set this into traversing media okay so this is how i can set new values and whenever i set this if i dump the whole person then i can see that this person now contains channel as well right there and the array has five length so there exists basically five elements in that array okay so in php 7.4 there exists null coalescing assignment operator so which is a very weird name but it's very handy feature so for example if i want to check if the person has address and if the person doesn't have address i'm going to set the address to unknown so i have to do like this if uh is set person address okay and i'm gonna put note sign right here okay if person address does not exist okay i'm gonna set the person address to be unknown okay and then finally if i just dump the person i will see that the address of that person right here is unknown okay but in php 7.4 there exists a shorthand version for that okay and that is double uh question mark okay so right here i'm going to write person address okay question mark question mark equals unknown okay so what does this mean this means that this double quotient generally is used for checking if the uh value is set or not okay so i can write this in the following way as well question mark question mark unknown so let's just remove this okay so which checks that if the person address is set or not okay if it is set then take the person address if it is not set take the unknown okay so if i comment out this thing and dump the person on the right side we see that it has address unknown and i can even make this simpler and put that question mark question mark right here refresh it and i see the exact same result okay so if i want to check if the array has a specific index or not i have to use that easy set function so if i want to print the whole keys of that array i'm going to use array underscore keys i'm going to specify person and this will give me the keys of that associative array person so refresh it and right here we see this is an array and here are the keys name surname age hobbies channel and address if i want to print the values of that array i'm going to use array underscore values function specify the person save it refresh on the right side and we see the values like the prey traversing 30 this is the hobbies value this is the channel and this is the address okay there is even possibility to sort the person by keys or by values okay so i'm going to use k-sort specify that person and which will change the person and sort sorted by keys so if we just print out the person we see right here that we see first address then age then channel hobbies and so on okay if we want if i want to sort that by values i'm going to use a sort okay save and refresh this and first i see bread traversing the introverse media then unknown and then we have agent hobbies okay so in php and uh yeah it's it's very common in php to work with um two-dimensional areas okay especially when working with databases okay let's have a look at the example of two-dimensional array so for example i'm going to create two do's right here as an array and each of the to-do element i'm going to make a sub array okay which will be associative area and each of the to-do element i'm going to give title to that which will be to do title 1 and give it also completed completed property which corresponds to true for example in this case so i'm going to make this a little bit larger move it on the oops move it on the right side just like this one and i'm going to duplicate this and create 2d title 2 with completed false okay and this is the associative area and very often we work developers with that associative areas okay this is this is how the data might look like when you receive from some rest apis or uh selected from the database okay and i'm just going to dump this and let's have a look together and we're going to have a practice on that of course so here it is how it looks like so area of two elements the first element is area itself with the title of this with completed of this this is the second element with the title of this and completed of this okay so that's all about areas let's move on and talk about conditionals okay let's open conditionals.php right here and on the right side as well and write couple of if else statements so in general if you have any experience in any programming language if else statements you know what is an e-file statement right so let's see how we can do that in in php so if in the parenthesis we write some condition for example if age equals to 20 okay and then if age equals 20 we just print something for example one okay so if we have a look in the browser we see one so that happens because the age actually equals equals to 20. so we can actually write ifall statements without these curly braces so if we want a single statement right here we can avoid that curly braces so i'm going to copy this paste right here and just remove these curly braces and it works in the same way we can even write this on a single line and sometimes like the developers write like this so i generally write with curly braces because it's more readable for me but it's basically a matter of your choice okay so we see like one and one right here so let me write in a simple if and then else statement so if for example age is greater than 20 then we write one if uh in other case else so which means in any other case we just write two okay so refresh it and right here we see two okay let's see what is the difference between the double quotation and triple quotation in php okay so i'm going to comment out the other things and right here i'm going to write if age equals 20 then let's just print one okay with br okay and another example is if age equals string 20 okay and if we just print these two for example both of them will be printed okay so we see one and two it happens because whenever we compare the variable two values to each other with double quotation only values are compared right now the age is uh integer 20 and we're comparing it to string 20 and because we are using double quotations the values are compared and it prints it prints two so it is actually true so if we just change this and put right here triple quotation this won't be satisfied because not only values but also types will be checked and compared okay so i'm going to paste something right here and look at this so age with a double quotation 20 is true age with a double quotation 20 as a string is also true h with triple quotation 20 is true because age is integer and we're comparing integer to an integer but age with triple quotation 20 is false because also types are checked okay okay let's see how we can use multiple conditions in the if statement so i'm going to write if for example age equals or is greater than 20 and salary for example equals to 300 000 in this case do something okay to something okay in this case it will it will not be satisfied because age basically is not more than 20. okay but if i change this condition into equals 20 this will print to something okay we can also use or operator so if h is greater than 20 or with two pipe or the salary equals three hundred so thousand do something okay in this case we will see do something because the first condition is false but the second condition evaluates into true okay so let's see how we can write ternary if and what is in general ternary operator so terminal ternary if operator is very often used for uh for con is a conditional statement for something very small not if we have a bunch of code to execute if something is executed if something is evaluated in the true so let me show you where i mean so if age is less than 22 for example okay and i put right here question mark which uh basically indicates that if this ev is evaluated into true then execute like a young for example okay return that string young otherwise like return old for example okay so this finally will print young right here because the age is definitely less than 22. okay if i change that a age into 25 for example this will print old okay because the else statement is actually satisfied so there is a way to have a short ternary operator as well so for example if we want to check if the age exists at all so i'm going to write if age question mark colon and otherwise like 18 for example so if i want to create a variable like my age for example which equals to age if age exists otherwise take the 18. okay if we just print right now that my age this will print 25 because the age exists and it is 25 however if i change that age into 0 for example and 0 basically is falsible value okay so age if age exists take that age otherwise take 18. in this case age is falsible value so age won't be taken will be 18 will be taken and right here we see this 18 okay so there exists null coalescing operator also and it's very useful a relatively new feature it didn't exist from the beginning of the php but it's very handy feature so if i want for example to check if the variable is declared or not for example if a name is declared okay if name is set then take out the name otherwise take out john for example as a name okay and we can assign this into my name okay and whenever i print these right now it will take john because we don't have name declared in the current variable right but there's a shorthand version for that so we can just write name question mark question mark and join okay which means that if name exists take out the name if doesn't exist take out the join so they are basically equivalent to each other okay let's see switch statements so right here i'm going to create a user role variable which will be admin and let's say that we support other roles as well like the editor a user and admin as well of course so i'm going to write a switch statement right here switch user role which checks we takes the user role and we have to write couple of case statements so if the user role is admin case for case admin okay we just print we just do something which is relevant for admin okay for now i'm gonna just print admin okay and we have to break right here okay so another case will be editor okay if the user role is editor let's just print editor right here and break as well so another case is user and let's just print right here user and break and we can have a default value which means in any other case let's just print invalid role okay so if i save this and refresh right here i see admin okay the following code will be executed if i change that user rule into editor and save and refresh this i see right here editor if i change this something like web admin for example okay this will print invalid role because that doesn't exist okay that's all about conditionals let's move on the next topic is is loops okay so let's open loops on the browser as well and see how we can write loops in php so i'm going to write a while loop okay while then inside the while we write some condition so while true for example okay do something which basically means an infinite loop because this true will always be true and the while loop will basically crash your browser okay don't run this because it will start an infinite loop but instead it's more relevant to have some condition right here which changes after some time into um two folds the while loops basically are the infinite loops basically sometimes are used uh in a in real programming okay so let's create right here counter which equals to zero and i'm going to create a while loop while counter for example is less than 10 let's print the counter okay and we need to increase that count okay so you can understand that first the counter will be printed as 0 then it will be increased okay after that the condition will be checked if counter is less than 10 and then the counter increased counter will be printed and so on and after 10th iteration the loop will be basically broken okay so we can manually break the loop if we want for example if counter reaches to 5 we can break the loop and it won't be executed so the break basically stops the loop okay so i'm going to comment this let's see do while okay do while has the following syntax we write do and then we write something for example echo counter okay and then we have the while condition while counter is less than 10 for example okay so i'm gonna comment this thing and we have counter zero and we do something similar but we need to increase the counter as well so here is the difference between while and to while so right now at the moment it will also print one two three zero one two three four five um until nine okay let's put beer here as well but the difference is that if i change that condition counter is less than zero okay in this case first it prints the value and then checks the condition and in this case it will be printed at least once okay but in our first example in case of while if i change this into 0 it will never be printed because counter is 0 if counter is less than zero and this condition evaluates into false and the body won't be executed okay but in this case it will be executed once okay let's comment out this all the things and see a for loop example okay for loop has the following syntax four then we write a statement which is right at the beginning of the for loop for example i equals zero okay then we write statement which is executed before every iteration of the for loop and if that evaluates into true we actually continue the for loop okay so if i is less than 10 and then we write a statement which is run after each iteration okay i plus plus okay so and let's just print i for example which indicates the counter and it will give us the same exact output what we had for uh while loop okay so this is how you can write uh for loops so let's see how we can write forage sometimes forage is very often used with with some arrays okay so if i have an array right here for example fruits array and i want to iterate over the fruits area okay i can do like this okay for each fruits is fruit which means that take each element of that fruits array as a fruit variable and right here i can write that fruit variable okay save refresh and we see banana apple and orange i can also take out the index if i want i for example corresponds to fruit so right here i will be index of that array elements and the fruit will be actual value okay so refresh this save and then refresh we don't print the i so let's just print i in that way br save and refresh and here we see zero banana first apple to orange okay so let's see how we can iterate over an associative area okay so i'm gonna paste right here an associative variable person okay and then let's iterate over that associative every person okay when we are iterating over an associative array sometimes we want to take out the key as well okay so key and value okay so this is the key this is the value this is the key this is the value so we want to iterate over that so i'm gonna do like this so just print out the key then space and the value okay however we're going to have a small problem right here because right here the hobbies corresponds to array so arrays cannot be converted into strings uh in that way just with the concatenation way okay we're going to have it notice right here array to string conversion so let's put beer here so right here we see that name is bread surname is drivers ages 30 and right here we see array to string conversion okay so that's a problem so however what we can do is that we can run an implode on that and implode that with commas so here we have it refresh it what's wrong yes this is the problem so right now i did a mistake so i put an implode right here but that implode is called onbread traversing in 30 as well okay what we can do right here is that we can write an if statement if for example value is array okay that value we can output with the implode okay just like this one echo implode with comma the value however if it's not an array we can print like we are printing okay right here so we just need to print a value so save and refresh and here we see so name bread surname privacy age is this and hobbies is tennis and video games that's combined with the comma okay so that's basically all about loops let's move on on the next topic okay i'm going to open the next topic which is functions let's open in the browser as well and okay let's see how we can create functions in php okay so i'm going to create a very simple function hello function hello which simply outputs hello i am sure okay now the syntax basically of the function declaration is pretty much the same in javascript for example if you're familiar so we write the function keyword and the function name then parenthesis and right here we write this curly braces so i'm going to execute that hello now okay which will print out hello i am zura so i can execute this multiple times and here we have the multiple outputs the purpose of the function is to avoid some code repetition and have a reusable piece of code which can be used from different different places okay also we can pass arguments to that function okay so let's see a function with the argument right here i'm going to create another function hello but i'm going to comment out this one because we we cannot have functions with the same names and right here i'm going to accept an argument of name okay and here we can write hello i am and the name okay fine now when we call hello we have to specify name for example zura save that and refresh and here we see hello i am zura i can call the same function with different bread with different names sorry bread for example and right here we have hello and bread okay we can also return the values from that function i'm going to write return here and in this case this code won't print anything because we don't have an echo statement so this hello function returns the value but we need to print that value to see the outputs right so i'm going to put pr here as well and here as well save and refresh and here we see hello i am zura hello i am red okay let's create a function to sum two numbers okay function sum which accepts a and b and i want to return the sum of the two numbers a plus b okay it is that easy i'm gonna call that sum pass right here uh four and five and that returns the value so we have to print these using echo and right here we see the 9. okay so what if i want to uh pass i want to my function to support many arguments like the in unlimited number of arguments okay so let's comment this and create another function sum which accepts basically uh many arguments so right here when i call that sum i want to pass multiple arguments just like this and i want it to return the sum of all just like this one okay we can accept the argument right here with three dot notation okay for example nums which means that take out all the given arguments and save in the nums as an array okay so right here i'm going to write nums okay save that and uh refresh right here and we see that array okay so i have a challenge for you so pause the video video and write a for loop right here which will sum up the given numbers and return that sum okay so just pause the video do this for several minutes and then come back to see my answer okay so here is my answer so i'm going to create a variable sum in which i'm going to save all the values the sum value of that numbers okay then i'm going to iterate over my numbers okay for each nums is num okay or just in and then i'm going to write sum plus equal n okay and finally i'm going to return that sum so finally when i save this and refresh in the browser i see right here value 21. okay let's move on and see arrow functions so arrow function is a new feature added in php 7.4 so in fact i can i'm going to take the following sum function and paste right here and just change this using arrow function okay so let's comment all this thing and i want my sum function right here to do the same thing but i'm going to use array reduce array reduce so in php there exists also functions like array filter array map and reduce and let's see how we can use reduce with the arrow function okay the array reduce accepts we need to pass two arguments first is the array for example nums and second we have to pass the arrow function okay the error function is syntax is the following fn parenthesis inside the parentheses we give carry okay as a now the first argument inside that function and then we accept the n which is the each element of that array okay and we just return carry plus n okay let's actually see what this will do i'm going to return the value of that from the function and if we just say that and refresh we see 21 but how this actually works the array reduce so on the first iteration it basically iterates over the elements and calls that given function for each of the element on the first iteration when it calls that function it passes the first argument first element of that nums array as a carry and the second element as an n okay we take that first element and second element and return sum okay right here this basically means to return from that function okay from that arrow function so we return first plus second which will become the carry for the next iteration okay so first plus second is a three so for next iteration carry will become three and n will become the next element which will be three okay then three plus three will be returned from that function which will be given to the next iteration as six and the end will become four and so on until the end of the array and finally this gives us this sum okay okay that's basically all about functions i wanted to uh show to you let's move on and see how we can work with dates in php i'm going to open on the left side dates php on the right side as well right here and let's see how we can print date okay so let's say that i want to print the current date so for this i will use the date function and we have to specify the format in which i want to print it so for example first print the er then month then day then hour minute and second okay let's put echo in front of that and refresh in the browser and here we see that date this is the current date okay so if i want to print for example yesterday so echo date the same format basically your month day hour minute and second but we have we can specify the timestamp so timestamp basically is number of seconds from 1970 first of january uh midnight okay so right now the time will return this is the current time in seconds okay and i can subtract a number of seconds for one day so for example 30 multiplied 16 multiplied on 16 and that multiplied on 24 which is number of seconds per day so if i save that and refresh and let's put beer here as well refresh right here we see that this is yesterday okay the same time but yesterday so what if i want to print the date in a different format so let's put beer here as well so echo for example date but i want to specify a different format okay so how i can do it in the following link there exists many different formats sorry about that okay so right here i can specify f j y h i and s okay so the basically time is the same but i change the date format okay and let's just have a look in the browser and this is october 12 2020 okay so and on the following link you can find more date formats and more in general more about dates and i really encourage you to check out that link okay so what if i want to print the current timestamp okay we have already saw this this is using time okay so let's print out this and we can see number of seconds since 17 since uh 1917 okay first of january so there's also a possibility to parse the date sometimes the date comes from the client from the forms very often and we want to parse that date okay there exists a date parse function for that and we have to specify right here the date for example 2020 um i know 10 for example 12 12 this is the month this is the day and this is going to be the hours for example 0 9 0 0 0 0 okay and this returns an array okay this is the parsed parsed date and we just print that parsed date and have a look in the browser and we see it is an array it has year 2020 month 10 day 12 hour minute second and it has couple of other information as well okay sometimes we have that dates in a different format and we want to parse that based on the different format okay so for example i'm going to paste this code right here so for example i have a date string which is february 4 2020 and the following time and i want to parse using that format okay so i will call a special function date parse from format i will specify the format right here in which that date time is and i specify the date time itself and finally this this will give me the same type of output yar 2020 month 2 day 4 and so on we have everything there we need okay that's all about dates i encourage you to check out the following links which will be on the github repository and let's move on on next topic the next topic is about including files so i'm going to close all the files right here open that directory on the right side include and require website skeleton so let's open this right here as well website skeleton right here we have two files so about php and index.php and this is a simulation of a website okay so we have two files and we can we have a header and we can navigate between these two pages so this is the home page which displays welcome to my cool website and some georgia tbc time zone okay the the temperature excuse me and we have also that about page okay and the header and the footer for that pages are the same so this is the header this is the footer and they are the same for both of them but if we can if we have a look at the files right here we see that the the html is basically repeated okay this is the about php this is the index.php and we have things repeated so we shouldn't have that so if i want to add a script tag for example in the head i had to do this in both places okay and we can actually do in a better way using php so what we need to do is take out that header and create a file for that and we can use that header file in both of the files okay let's do this i'm going to create a file called header php but i'm going to create that in a partials folder okay inside partials let's create header php okay so i'm going to take out that header and paste this right here okay and now in the about.php and in the index.php as well i can use that file okay how i do this first of all we need inside this php opening and closing text and then i'm going to write include okay i want to include a file which is called partials slash header php okay let's uh let's actually take out this and do it in about okay save and refresh and i can see the same result nothing was actually changed because that works fine so if i have mistakenly typed incorrect file path on about page we're gonna see an error right here okay so for including files there exists basically two ways to include the files one is include second is require okay so what is the difference between include and require so if i have this code written using include on the right side in the about page let's change this into a non-existing file okay and if we are including file which doesn't exist then it gives us this warning the file was not found but the rest of the code basically is executed okay so it prints about us and we also see that footer okay however if we change this using require okay this is this has different purpose so in this case we will see fatal error right here and the rest of the code is not executed anymore okay so when the file is not found using require it basically stops the code from execution so we should have uh require when that file is absolutely necessary for uh for the website for the functionality okay and we can have include when it is not absolutely necessary okay there also exists include ones and require one's methods uh statements okay operators so if i duplicate this if i fix the path first of all and duplicate this and reverse in the browser i see this header twice and if i have a look in the page source i also see that doctype html twice okay so if i change that include once include into include ones okay in this case no matter how many times you're including that files the php will check if it's once included it won't include anymore okay and this is how it looks like okay so basically in this case the perfect example will be to write an include once for here and here as well and we probably need to create footer as well so i'm going to create right here a footer paste this and include that footer right here footer php and in the about page as well so let's copy this code and paste right here so now we can see that we don't have any code duplication okay and this is how our website is looking like okay it works in the same way as it was working before okay the second usage of including that files one of them is including in the html and second way is to have a reusable piece of code which can be included on different from different areas okay so for example i'm gonna go into that functions in the index.php and let's say that i'm developing a math library for example and i'm going to create math.php okay inside that math file i'm going to create a couple of functions working with numbers okay for example ed which will accept a and b and return sum of that okay a plus b and let's create second one as well which will be subtract which will accept a and b as well a and b and return a minus b okay so and this is the math library and i'm going to use that math library in the index.php okay so right here i'm going to write include once that math.php okay and now i can use that functions for example echo aid four plus five okay and echo subtract five and four okay let's put b here as well let's save this and let's open the corresponding file right here functions and here we see nine and one however what's the correct usage right here it's not include once the correct one so if that math file was not found it doesn't make any sense to continue the execution and because the other ones will also print that error okay so if the math doesn't exist this one will give us the warning because this is included not to require but the other ones will give us also error right here okay fatal error call to undefined function 8. so in this case the best will be if we have require okay and when the file was not required it won't execute the rest of the code and we will see only one error okay and also the best will be if we have right here require once because if we have this required and required couple of times then we're going to have a different error cannot really clear it because it's already declared okay so the best example will be to write such kind of libraries in general using require once okay save reload and everything works fine okay that is all about including files let's move on on the next topic and see how we can work with the file system okay let's open that file system folder right here index.php i'm going to close the others and open that on the right side as well right here fs okay perfect so first of all let's explore couple of magic constants and what are these magic constants okay so magic constants are constants which change the their value based on the execution context okay so for example i'm going to print right here and two magic constants deer and file echo file okay and let's print the third one as well which will be line okay so what what will be the output of that let's have a look so first of all that magic constantine prints the current directory where that file is located okay in this case that prints that 11 fs the file magic constant prints the current file from which we are printing that everything and that magic constant line prints the line on which this is written actually so if i put a couple of enters right here that little magic constant line moves on the next line seven and that finally will print right here seven look at this so these are the magic constants okay let's see how we can create directory in php so for this we have to use a function mkdir and we have to specify a directory name test in this case let's save this and refresh on the right side and let's have a look here we have it so test directory was created so what if we want to rename that directory so let's comment this and i'm going to write rename okay so it will take that test let's take the test directory and rename into test two okay and this will do the renaming so if if i want to delete delete that directory and we have to use rmd and we have to specify that test2 directory so at the moment when rename will happen the directory will be called test2 and it should be removed okay so let's save this and execute this and we don't see that test folder anymore because it was first renamed into test2 and then it was removed so what if i want to read file and its content so for this we have to use a function file get content file get contents we have to specify the file name in this case lorem.txt let's say that we want to read that which has some dummy text right there okay and this basically reads the file and returns the output of that file okay and we can directly send that output to the browser so save that and refresh and we have to comment out this because there are no test folder anymore refresh it and here we see that output the content of that file okay so there exists other ways to read the file in general and i really encourage you to check out the following link i'm going to open this link also soon okay let's see how we can list the directory and read all that files and folders inside that directory okay so i'm gonna write here scandir and specify the directory and which will read the directory and show a list of all files and folders inside that directory okay so let's call it files variable and let's print that files variable save and refresh and right here we see that list so what does this dot and double dot mean so this will be always there whenever you scan your directory and this dot basically indicates the current directory and double dot indicates the parent directory okay and besides that we have also index php and lorem.txt in the current directory so if i pass right here double dot slash which means that list the parent directory and save and refresh these here we see all the files and the folders which are in the parent directory and this is that directory what we see right here okay okay perfect let's see how we can write content inside that file okay so we saw file get contents now let's see file put contents so we specify some file name for example sample.takesteam and we specify content some content okay when we execute this it will create that sample.txt right here here we see if we open we see some content right there okay so we can combine that file get contents and file put contents together and read the content and append something at the bottom and put it uh in the um file put contents okay so the file get contents also supports to get the content from the url so for example let's open json place holder okay which is the fake rest api and i'm going to scroll down right here and find the resources for the users and copy the following link and i want to read the content from the following url okay so i'm going to use file get contents specify the url and that fetch the data from that url and save it in a variable like users json for example okay and we can print that user.json right here refresh it and scroll down and here we see that user json right here it starts so if we have a look in the page source scroll down we see it in a nicer way this is the user json fetched from the json placeholder and the json basically is a type of the um how the data can be exchanged and how the data can be stored okay and we have also a possibility to convert that json data into an array and we have to use json decode for that so we specify user json that will convert that user json into an associative array into an array more correctly and let's just print that users okay save that and refresh it and scroll down and right here we see so um right here we see that this is an array of 10 elements the first element is the object which has id name username email and address which is an object itself and so on so each individual user will be right here okay by default when we call json decode this converts the associative arrays into objects okay but we can specify right here uh false okay uh for false or true a source false no we can specify true right here which means that to convert into an associative array and right here we see that this is not object anymore it is an associative area okay with key value peers okay let's comment this thing and basically there are a couple of other useful functions like file exists for example which checks if the specific file exists or not and i'm going to specify right here for example sample.txt which will return true because we just created sample.txt okay but if we specify right here in an existing file it will return false obviously we can also check if the specific folder is directory or not and we can specify for example test if test is a directory and this will return false because the test directory does not even exist right here okay so this will return obviously false so let's open the link right here we have a lot of functions so i really encourage you to check out the following link and experiment with the functions so right here you can find basically everything about the file system how to get the file size how to get the file modification time and many many others so i really encourage you to check out the following link okay we cannot cover all the functions in this several hours course okay let's move on on the next topic and the next topic is object oriented programming so i'm going to open that index.php right here let's close the other things and open that on the right side as well oops and let's create a class and an instance in general what is a class and what is an instance the class is a blueprint it is a template okay you can also think about it as a new data type okay and out of which we can create the variables of that data type and that variables are called instances or objects sometimes okay so whenever we create class we define some properties and functionalities of that class and then the instances of that class will have that properties and functionalities okay for example if i create a class of person okay and that person has a public property name and public property surname and private property age for example okay so these are the properties of that person class and how can i create an instance of date so i have to write here person equals new person okay so we have to use the new keyword in the class name with parentheses and that creates that person class and let's dump that person class excuse me that is a person instance created out of the person class okay we can even call this just uh just p okay just p just like this one so i just wanted to show you that the variable name cannot should not be the same it cannot be the same it may not be the same okay refresh and right here we see that object person with name surname and age which is private property okay what does this mean that it is a public or private so these are called access modifiers there also exists a third access modifier which is called protected which is more relevant when we see inheritance okay so i'm gonna set right now the name and the surname of that person class so i'm going to write here p dot name equals bread okay and p dot surname equals traversing okay let's save this and refresh in the browser and we see that name and surname is bread and traverse okay so i can actually access each individual property right here and print that so echo p name i want to print out the person name for example refresh and here we see bread okay so if i want to create different uh persons with different names so i have to repeat this code okay p equals new person i'm going to call this p2 okay and i have to specify right here a different name and surname john smith for example okay and they will be all of these instances of that person class will have the same properties but they might have different values for that properties okay it's very often used to create a special function and use that special function which is called constructor with the classes okay i'm going to create a constructor right here and specify two arguments name and surname so constructor is a special function associated to the class which is called executed immediately when the instance of that class is created okay in this case we create an instance two times right here new person and right here new person we call these two times so every time we create an instance that constructor function will be executed okay and whatever arguments is given inside that uh creating instance right here that will be passed down to the constructor okay so for example we can delete these two lines and pass bread and traversey right here and bread will become name and traversing will become surname and i can take that name and surname and do some actions with that so i can print if i want for example name space surname okay and refresh that we have couple of other errors uh okay this happens because on line 16 we are creating a person instance and we don't give it a name and surname let's comment these lines yet refresh and we see bread traversing which is printed from this line okay instead of printing it's more relevant to save this information in a properties of that class so i'm going to use the keyword this which basically indicates to the instance on which that constructor is called okay in this case the constructor is called on a person p okay that's why this will correspond to p so this dot name not dot but the arrow so this arrow basically is a property operator so it's called a property operator so this is used to access to the properties and methods of an object okay this name equals name and this surname equals surname so we save that let's remove this echo we save that and refresh and we don't see any outputs but if we print right here p we will see that this is a person and it has bread and traverse okay so the given name and surname was taken and saved okay the class can also have methods which are basically functions associated to that class so for example right here i'm going to create a public function a set age which will accept an age as an argument take that age and we'll save in a property okay very often when we have private properties we create setters and getters to set the value for that private property and get the value we cannot directly access that private property out of that class so if we try to write p h equals something i don't know 30 we're going to see an error because we cannot access that private property okay so we have to use uh now a public function which we created right here public set age okay and we specify that 30 which will take that age variable and save it in a property so after this if i print the person we see that person has an age of 30. and i can create another public function get age which simply will return an h so return this age and this is called getter okay and now i can print p get age save and refresh that and we see 30 right here okay let's uncomment now that second person and let's specify right here that john smith in the constructor okay and we have that second person p2 save and refresh and here we have it so now let's see static properties and static methods so i'm going to create right here public static counter okay which equals to zero and whenever an instance is created i'm going to increase the counter but pay attention to this new keyword which is called static so static properties and static methods belong to the class itself not the instance okay not the object created out of that class okay and if i want to access that static counter i have to use a self keyword self counter plus plus so whenever we create an instance of that class we create we increase that counter property okay and i'm going to create right here as static function as well public static function get counter and i'm going to return self counter okay and now down below when when we created two instances of that person class i'm gonna print person class counter okay so we access to static properties with this double double colon okay save that and refresh and we see two which means that the counter is two because two objects are created out of that class which is quite accurate let's call that gate counter statically using this double column save and refresh and we see two right here okay so there are much more to explain about the classes but i'm not going to cover all of them right here because this is not like the full course about object oriented php okay these are just basics let's see a couple of other examples like the inheritance so i'm going to create a file inside that object oriented folder and call it person very often when we have a class that class is in its own separate file so i'm going to take that person class and move it in that file okay so here we have it and we can if we want to use that person class we have to include it or require it right here in this case the best example will be to require once right here not include not include ones but require ones so i'm including i'm requiring that person and this will work in the same way so we have the same output right here okay so i have uh i should also mention that since php 7.4 we have possibility to specify the types on the properties so for example i can write that the name is string surname is a string and age is integer and we can also specify that on counter that it is an integer as well okay that is because of php 7.4 so if i declare a variable with the type int for example and i want it to be sometimes null values okay for example when i create the instance i want to specify that this age to be null this won't be possible this is not possible and we're going to see an error right here that the age is an integer and you cannot assign now to it but if we put a question mark in front of that the type it means that this is an integer but it also accepts null values okay so and if we do this the error will disappear basically okay so now i'm going to create a second class which i'm going to call student okay and let's remove these things and i'm going to extend that student from person so i'm using inheritance okay so the student class is a child class of the person so first of all before we are using right here's uh person class we have to write require right here as well okay fine now in index.php i want to include that person as well okay so not the person but the student excuse me okay here i created the student i'm going to comment the person code okay and i'm going to delete that as well and i want to create now an instance of the student okay student equals new student okay but pay attention one thing right here phpstorm basically tells me that required parameter name is missing so because the student extends the person the student also has a constructor inside its parent class person okay and that constructor accepts name and surname so we have to specify name and surname when we create an instance of the student okay let's create bread uh traversing okay so that will work the error basically will uh will not be displayed also one important thing to notice is that uh because we have right here require once that's correct way and that's why we don't see any error if we change that into require now it turns out that we are requiring we need to also change this right here we are requiring person class twice so right here we include we require that person class then we require student and then student requires person so if we have refresh in the browser we see that error cannot declare class person because the name is already in use okay that's why require once is the best example in this case now let's say that i want to add couple of other properties to the student for example public student id okay and that's going to be string now i want to pass that student id when i create an instance so right here i want to pass this student id as well so in the student constructor we want to accept a third argument as well so now i'm going to create a constructor public function construct and basically phpstorm autocompleted this for me and it's called the parent constructor and the parent constructor is person okay so but we need to accept the third argument right here as well which will be student id okay and i want to take the student id and save in this student id okay and then call the parent constructor and pass it name and surname which will take and save its in its own name and certainly okay so and one more thing i want to show you is that we can have protected properties as well so this age property cannot be accessed outside of this person class it cannot be accessed right here it cannot be accessed right here it cannot be even accessed in the student class but if i change that age property into protected okay after this i can actually access the these in the student class so i can write this age equals to 18 for example save and refresh and we don't see any error it works just fine and we can print that student right here save and refresh and here we have it and we also have that age protected which turns out to be null so it is now because we set right here 18 but in the parent constructor it is set to null so what we can do is that first call the parent constructor and then call our property sets and the age property will be 18. look at this however if that age property is private when i try to access right here phpstorm also gives me an error about that but in the browser we we will see um right here we should see an error we don't actually see that error okay let's see and i think that happens because it dynamically creates that private property okay so we cannot access that private property outside of that person class but right here it created its own property of that student okay so there is age 18 and age person private this age comes from the person and that age belongs to that student okay that's all about object oriented programming as i mentioned it's a large large topic and it can be covered in this short video so i really encourage you to find out more about this there exists a lot of videos and a lot of resources to read about that okay let's move on on the next topic the next topic is crl c url so i'm going to remove this and close all of that index.php and let's open crl on the right side as well so here we have it so generally what is crl crl is a tool which gives you possibility to interact uh remotely to other services to other resources okay so for example i want to get the information from the following url so i i'm gonna use serial for that we we have already seen that i can actually get the users uh from that url using file git contents right but sometimes file gate contents is blocked in terms of some security policies okay and filegate contents also cannot be used if we want to pass some additional headers to the request or if we want to post some information it can be used for that okay this is the place where we need to use c url so i'm going to use c url init function to start this url and i'm going to specify right here the url that i want to start it on the following url and this finally creates a resource and returns that resource okay so we have seen at the beginning when i was explaining variables right here that we have seven variable types like the the following ones and we explored these five immediately and later we explored arrays we explored objects about object-oriented programming the instances are basically objects and here is the resource the resource basically is the following thing okay which is returned from this url okay so we created that resource and now we want to uh set a couple of options on that resource so i'm going to use crl set opt function specify the resource on which i want to set the option i'm going to specify also constant crl opt return transfer and that corresponds to true so basically on that resource i set the following key to be true and after this i'm going to call crl exec which makes the execution on the resource and returns the result okay that's the user's json and we can immediately print that result save and refresh in the browser and here we see that result so view page source and right right here we have it okay so if we want to get the status code of that we need to use crl get info function and specify the resource okay so if we just call that function just like this one this returns a lot of information and we can print that and have a look refresh and we have a lot of information right here the url and the content type and the header size and the http code and so on okay but when we call this url getinfo we can also specify serial info http code okay h c url what's wrong crl info http code okay this one and finally this is the response code so i'm going to call it code save and refresh and right here we see that response code okay so when we make a serial execution and get the result then we need to call serial close okay crl close let's provide the resource after we call that serial resource we cannot actually get any info on this url so this code is okay and it works but if i put that url close before that serial info right here this code returns basically boolean false because the resource is already closed and we cannot read that okay so now i'm going to make a post request on that endpoint to create the user in the following api okay so for this i'm going to create crl init again and in this case i don't pass the url i'm going to show you a different approach this returns a resource okay then i'm going to call crl set opt we have set opt and we have set opt array so in this case i'm going to specify set opt eram provide the resource and array is the second argument okay and right here i'm going to specify serial opt a url so the url on which i want to make request is the following okay crl opt return transfer indicates true which means that i want to actually get the response okay crl opt post so i have to specify that this needs to be a post because i'm going to create a new user okay serial opt post fields are the user which i want to actually create okay now i'm going to create a sample user or i'm going to copy and paste that sample user and it's going to be an associative array like this one and inside the post fields i'm going to specify json encode user okay so this is the user i want it to be created and after this i call crl exec pass the resource and that finally creates the resource and this returns also result okay and we can close this url see where i'll close on the resource and we can print out the following result which will be the user created in that api save and refresh and down below somewhere right here let's comment the other code okay comment the following refresh and here we see that so this basically is okay what is this actually so this is no this is not correct so yeah one thing i missed right here is the http header so right here we get ver very weird response okay that's because we haven't specified the http header so we have to specify right here serial opt uh http header okay we need to tell the api that the content i'm sending to you is json okay so we have to specify right here in array content uh content type i'm specifying right here is application slash json okay and comma right here okay so using this i'm telling that i'm sending you a json let's save and refresh and right here we see that user so we'll page source and this is the user which was created in that api in that json placeholder rest api okay and the id was assigned to that user which is 11. okay so again serial is very powerful tool and can be used for many purposes it can be used for uploading files downloading files uh for passing some authentication and so on okay there are a lot of tools built on uh crl and i encourage you to check out more about this and find out okay so let's move on on the next thing which will be already a project and we're going to create product crud application and we're going to do this three times okay so first we're going to create this with the easiest possible way with the knowledge we got so far okay we're going to learn also many many things during building this project like working with the forums uploading files and so on and after this we're gonna re change our code modify our our code and make it more optimal and much better than it was in the first version and then we're going to learn also a couple of other things like autoloading and composer and using that tools using object oriented programming we're going to come up to custom routing and mini music framework and we're gonna build our product screwed based on that it's gonna be the best among all these three versions of the project okay let's start and first we have to create database in mysql and we have to create products table so i'm going to open right now phpmyadmin which is a web-based client for mysql and we have to create database so on the left side right here we have existing databases so i have a little bit more probably you have if you have a fresh new installation of xampp so let's just create new one hit that new right here let's just call this products underscore crowd and i'm going to choose utf-8 mb4 unicode ci which works best for me in all in all cases like so let's just create this and we have to create also table for products so i'm going to call the table products and i'm going to add six columns right here and hit go so the first column which will be id that's going to be an integer and i'm going to tick right here that it is an auto increment so it will also pick up the index primer so that's going to be our primary key of the table we're going to have title which will be varchar okay and let's give it 512 maximum length and that should be required so i'm not going to tick that checkbox okay it should be unticked so we're gonna have description as well which will be a long text or text let's pick up long long text so let let's give it a long text okay and right here i'm gonna make this optional okay take the checkbox we're going to also have image which will be a varchar of 2048 and i'm going to make this optional as well and we're going to have also price of the product which i'm going to make decimal of probably ten by two okay and this is the maximum okay let's give it 10 by two but the price should be required and i'm gonna create the last column which will be create date so whenever we add the product list will be picked up and saved in the database automatically so i'm gonna set this datetime okay so here we have let's have a quick overview everything looks good okay so scroll down and i'm gonna hit the save okay so the table was actually created okay now let's create a couple of records right there so i'm going to go into insert and the id will be picked up automatically so i'm going to leave this empty in title i'm going to write iphone 11 for example this is the first product we are adding in the description i'm going to leave empty the image i'm going to leave empty in the price i'm going to write 2 000 for example and the date basically i'm going to set this to current current date okay let's add second for example galaxy oops galaxy s20 i'm gonna leave description and image empty the price pay basically will be following and let's choose the current date and let's just say this so if we go in the browse we see these two records in the database okay perfect now let's start implementing our crowd application so i'm going to open right here that 14 product crud and let's open now php store i'm going to open this on a full screen as well and start so right here this is the index.php and whenever we open that index.php we would like to see the product list okay including image title and price the description might be very large so let's don't display the description in the list so i'm going to right now use bootstrap for user interface okay so let's open getbootstrap.com go to the documentation scroll down and i'm going to choose that starter template copy this one and paste in the index.php okay so we don't actually need uh which version is this by the way so yeah this this looks good so yeah we don't need javascript actually we're not going to use that so i'm going to remove all script tags from here we will need css to make it a little bit nicer and i'm going to change the title into [Music] products crud okay now we need to display table right here okay so i'm gonna choose a table design also from here scroll down and i'm gonna pick the very first one and paste right here let's format the code and let's open this index.php in the browser and have a look so this is how it looks like obviously we don't have the bootstrap css included properly okay let's inspect and see what's going on refresh that okay something is wrong so let css is not included refuse to apply stance because the mime type application xml is not supported stylesheet very strange let's open this in a new tab okay i think bootstrap has some bugs at the moment okay so let's search for or let's just download the css but let's search for cdn bootstrap cdn that should actually work so right here let's pick the following the following link and paste this right here okay let's refresh it and here we have it so something was wrong with that link which we just grabbed from the bootstraps official documentation i don't know why to be honest but yeah we have the results so this is the product squad so i'm going to also create up css right here and put there just a little bit of padding on the body padding 50 pixel let's save it and i'm going to include that right here link to be up css cool so we have that little bit of padding okay perfect now what we need to do is to make a query in the database right here select that products and display in the table and of course we have to adjust the columns which are displayed right here okay so let's first make a connection to the database and select that products okay and just dump and to have a look okay so again i want to highlight that we are right now building a version which uh very beginner would build okay so we have to go with the easiest possible ways and the easiest possible way right now is to create php tags right here and make a connection to the database okay so we're gonna use pdo for this so pdo basically there are two ways to make connection to the database one is mysqli and second is pdo i really encourage you to go with pdo because it is more powerful it supports multiple databases it is object oriented and there are a couple of other advantages okay so how we can connect to the database we have to create an instance of the pdo class so pdo is new pdo and i'm going to specify a couple of arguments right here first is dsn string which defines the connection string of the database so i'm going to specify that i want to connect to mysql database okay the host where i'm going to connect is localhost okay we have mysql installed locally okay the port i'm going to connect is 3306 this is the default port of mysql okay and that port is also displayed in xampp control panel okay we have to also specify the database name on which i want to connect and we called our database to be product squad so i'm gonna write here products products products crud okay so this is the first argument which is called dsn string and the second argument is the user so the user on the xampp installation in most cases in all cases basically is root and the password for windows is an empty password so using this we actually already establish a connection to the database but we need to tell pdo what should do if the connection was not successfully done okay so i'm going to specify right here on pdo set attribute and we have to specify pdo at arrow mode which means the attribute of error mode to be pdo air mode exception okay so when there is some error during that connection just throw an exception okay so let's just save this and refresh the browser and if we don't see any error this means that the connection was successfully established we're gonna show this so refresh we don't see anything which means that we're good but if i change the name of the database okay so let's add like s one more is right here save and refresh and here we see unknown database products with double s crud okay so this tells us that we successfully connected to the database now we need to make a query in the database and select all the products okay so on pdo we have to call prepare okay we can actually do this using exec but it's not very uh good way and very like best practice okay so exec is more recommended to make some changes in the database schema okay if we want to select let's always use prepared statements so in the prepared statement i'm going to specify the query select everything from products and let's just order them by the create date in descending okay order by create underscore date descending okay so this prepare method finally returns a statement okay which is an instance of pdo statement and on that statement we can actually call execute which will make that keyword in the database and then on that statement we can call fetch all method and we have to specify right here how i would like to fetch that okay and i'm going to specify fetch assault which means that i want each record inside the table to be fetched as an associative array okay and let's save that in a variable of products and i'm going to dump this right here that products array and let's have a look in the browser so here we have it so we have an array of two elements okay and we have two records in the database as well and each of the element is an associative array of uh id the column name and the value so id is one title is iphone 11 description and image are now price is this create data this and here is for the second one okay now we just need to iterate over each element and just display them in the table okay so let's remove this for dump scroll down where we have the table and first let's adjust the columns so let's put image first and put then title then put we don't need description so let's just put price let's put right here create date as well and put their actions column where we're going to put edit and delete buttons okay so we have totally six columns in the first column we display just the index of that product okay now we need to iterate the products we just selected right here and display them properly okay right here where we have these tr elements three tier elements which is copied and pasted from bootstrap let's just leave one and we need to put that tr in the for each okay so let's just cut this and write php for each okay so we have to specify uh products i want to iterate over products and i'm gonna call each individual product name of product and right here we're gonna output the tr which i just copied but i'm gonna right here close the php tag okay right here and i'm gonna start new tag oops right here okay so in between these four each start and for each end i can write in html okay if i just save this in refresh in the browser we see two records the same ones so that happens because we have two products the four each loop iterates two times and it displays the same tr okay i'm going to show you also second way how you can write for each which is generally what i prefer and i generally write like this okay so we put column right here okay and down below i'm going to write end for each so this is generally how i write inside html files the for each okay but you can choose the previous one the this one if you prefer okay so perfect now we need to display index right here so let's take out the index of this for each loop so i'm going to call right here i and the i basically is an index and the product is the product and right here we just output i plus one because the iteration starts with zero and we don't want zero to be displayed in the first column we want it to start with one okay in the second column we display the title okay so the product each product is an associative area so we just access the title of that product so i'm going to delete these two lines and just duplicate this few times we need right here excuse me the first we need image and then title so we have not actually implemented image yet so i'm going to leave this td empty then we display title then we display price then we display create underscore date and right here we should display two buttons one for edit and second for delete okay so let's go to the bootstrap documentation for buttons and right here we can choose the buttons we prefer i'm gonna go with outline buttons the following ones so i'm going to copy the very first one and paste right here and i'm going to call this edit and i'm going to just duplicate this and change the primary into danger and call this delete okay so let's just save this and have a look in the browser refresh and here we see the products okay the image is empty index and title and everything is displayed properly i'm going to change the button size into smaller ones i don't want that large buttons btn sm save refresh perfect okay let's go ahead and add one more product and i'm going to call this iphone se probably let's give it a price okay and let's give it date as well and click the go and it was inserted refresh it and here we see that s e as a very first one because we are just sorting this in a descending order now let's implement creating a form create form of the product so first let's add create button right here above the table so i'm going to create a paragraph and inside the paragraph i'm going to create a button which will have a class of btn btn success these are just bootstrap classes and i'm going to call this create so have a look here we have so let's just call it create product and we have to also change this into an anchor link instead of a button because we're gonna add ahref right there and i'm gonna put right here create.php okay so whenever we click on that link it should open create.php so if i click right now it's tells me not found because that create php doesn't exist so let's just create that so right here we need that create.php okay inside that create.php we have to uh include that bootstrap and everything basically regarding styling what we have in index.php okay so we are doing this as a beginner and the main thing for us is to achieve the final goal and have it working so and let's just copy everything in from index into create okay and adjust couple of things so we will need connection to the database um so but we don't need to select the product so i'm going to remove that select we will need that stylings in bootstrap and up css and that should the title should be basically create new product okay let's just do like this and we need instead of a table right here we need a form okay so let's open bootstrap documentation and search for four okay scroll down this is the very basic example of the form i'm gonna copy this and paste right here format the code and have a look in the browser so here we have that create new product but we need to adjust that form elements right so i'm going to remove that for and id and make this as simple as possible so we don't want id i'm going to remove that oops i'm going to remove that area described by so this thing so i'm going to remove that id or we just don't need that small at all so this is going to be email no this is going to be a product title okay and this should be input type text and we need to give it a name as well but i'm going to leave this without names to show you one important thing so then i'm going to just delete everything and copy and paste this okay few more times so one will be for title second will be for uh actually the first one should be product image which will be input type file then we're gonna have title then we're gonna have description uh which should be text area it should not be input okay then in the texture it doesn't need that type then we're gonna have product price and that is basically all the product price should be number okay and i'm gonna give it also step 0.01 okay so that the price of the product can be can include decimal uh numbers as well like 5.25 or something like this okay so let's have a look in the browser so this is the product image and let's just remove the form control on the input type file we don't need that refresh so and we put br right here so that's good enough so we have that so we have product title description price and that is basically all okay so whenever we hit the submit we want to get that submitted information and create a product in the database in the mysql okay how to do that so right now if i click the submit it actually submits the form but nothing happens okay in the form we have to specify two attributes so the action defines where the form needs to be submitted and in our case we're going to submit on the same file so the create php should be where the data should be sent okay if we want the same file to be used for submitting we can even put this and leave it empty okay and the second attribute is method generally when we crea when we create or update or delete something in the database we should do this using method post okay it is much more secure and i'm going to show you the difference between get and post first let's leave it get and by default if you just don't provide the method attribute it is get so let's leave it get and just hit the submit and nothing basically happens so that because the input fields does not have names whenever we submit that the form takes the names of the input fields and that's why we have to specify write your names and that's going to be image this will be title this will be description and this will be price save it refresh and now when i hit the submit look at this in the url so right here we see question mark image equals then in symbol title equals n symbol description equals n symbol and price equals and that's the end so this what is this so this is called very often query string i'm going to copy and paste this right here and just explore this okay so here we have it and keyword string starts with question marks so we don't need that question mark and qr string basically is key value peers separated by that end statement so in our case the key is the image and the value is empty string okay so right here we don't have any value for image so it is an empty string then we have an end symbol and then we have title equals to an empty string and description equals to an empty string and price equals to empty string so if i just put some information right here okay so for example um i don't know one plus one plus description some description and let's provide some price hit the submit button and look at this so in the url right now we don't see empty strings let's paste this right here we see image is empty but title is one plus and description is some description and price is one two three okay so this is how we can possibly get information and this is um the in basically when you pass information using method get which we specified right here the data is displayed in the url so that's why if you want to pass some sensitive information like the username and password when you do a login form you should not use get you should also not use get when you want to make some changes in the database the get using get will be a good example if you want to make a search form for example so you make a search form and we're going to do that search form also in that products crowd application and you'd make with with the method get and basically in the url there will be written the search keyword and that's it so the advantage of having search uh inside the uh inside the qr string or making the search form using method get is that it is in the url okay so when you submit the form using get the parameters are in the url and if you just copy and paste that url and send it to someone else he or she can see the same information what you are seeing okay for a post nothing is added in the url nothing is displayed in the url okay so we need to do this with the method post but if i do this but before i do this i'm going to show you um the information how i can get the information from the gate so i'm going to use a super global get so in php there are a couple of super globals and all of the super globals have the following syntax so they are variables like they start with the dollar sign and they uh in the naming they have underscore and then some name like cookie session server get and so on in this case we went to get okay so let's dump everything from the get save and refresh and right here i see all the sent information which we also see in the url okay so if i change something and right here print image is equal test dot png for example we see that imagetest.pngb png is just provided right here as well if i remove title from here and hit the enter title also disappears okay basically everything what is displayed in the qr string after the question mark is get and you can get that information from the super global get okay but as i mentioned in this case we want method post so i'm going to change this into post okay so now i'm going to remove this question mark and keyword string and basically get is empty at the moment and now i'm going to print post so underscore post let's fill up the form this is going to be one plus some description sum price hit the enter and here we see the post information okay that's perfect now we want to take that and save in the database but we also want to pass image okay so let's first do this without image and then add an image there okay so we have title description price uh title and price are absolutely mandatories so we can actually validate if the title and price is not provided then we're going to throw an error okay so we would like to take that information title description and price and send it to the database how to get that so we have all this information in the post so we want to take that from post so i'm going to create right here title equals post a title okay i want to take out the title from post and we also want to take description from post and we want also to take price from post so we have that information and now we're going to make an insert in the database so for this we create prepared statement using prepare method on pdo so we write insert into products okay we want to insert in the following columns title image description and price and create date okay we want to insert in these columns and we have to right here specify what's going to be the values when we're going to make an insert okay so values needs to be some sort of strings okay very often beginners take that values which are submitted and put directly right here okay so imagine that the title is one plus okay or just make it very simple and let the title be test okay so the test needs to be passed right here okay and it must be written in the single quotations okay like test something like this and the same thing happens for image and right now we don't implement image at the moment so i'm going to leave this empty string and the description needs to be some description and the price needs to be some price okay and we also need date by the way which should be the current date okay we're going to implement the date as well but we have to put right here variables instead of these hard-coded strings okay so very often as i mentioned beginners take the values and directly put this right here okay so we we are using right here double quotations so we can use the variables inside the string okay for image we leave empty for description we can write the description for price we can write the price as for the date we can create a separate variable for that date which is the current date and we're going to format the current date as the mysql needs so mysql needs in the following format vr month day hour minute minute and second okay and i'm gonna pass this date in single quotations as well because when we make an insert in the database everything must be a string well the price must not be string it can be it because it is a decimal it can be just like this without that single quotations okay so we have it prepare and basically we don't so here is important thing so if we do like this and very often as i mentioned like the beginners do like this they also run with exec so this exact take takes the following query and directly runs it in the database and if i execute this we're gonna already see a record in the database so let's just save this and refresh so continue resubmit the form and have a look in the database and here we see that oneplus with description and image as an empty string and the price and the date so everything looks good so why we should not do this approach okay so the reason is that just putting the concatenating that variable with the qr string is very unsafe okay because whoever is filling up your form may provide sql injection code and that can cause dropping of your whole table or deleting some data or things like the bad things okay so we should not do modifications of the uh database data using this exact method and using this concatenation okay whenever we get some data from the user and we want to put that user in the database we have to use prepared statements so i'm going to right here right here change this into prepare okay and that's going to be insert into products with the following columns and instead of values right here and that should be by the way called values okay so i'm going to call i'm going to create named parameters okay that's the feature of pdo so column title is the first name parameter column image is the second column description is third column price and column date so all these are named parameters and finally this prepares the statement and returns that okay so what do we need to do right now so we need to save this in a statement variable and on that statement i'm going to call bind value method okay so in the bind value i just provide the named parameter for example title and the value i want to buy instead of that main named parameter okay so i'm telling to pdo statement that hey the title named parameter is the following value okay and we have to repeat the same thing for others like image in this case is an empty string we're going to implement this in a moment so description is description we need price as well and date that should be the following variable okay after this we run execute method on the statement and finally this makes a change in the database writes an insert in the database and that's basically all so if i just refresh the form right here and have a look in the database we can see that oneplus second time right here so if i continue refreshing this okay the records will be made in the database okay but our code is not perfect simply because if we just try to open that form it prints a lot of errors and why does this happen okay so i'm gonna pause right here and think about it why does this happen okay this happens because we don't have anything in the post the post basically is empty so when we are opening that form the title description price on the following lines seven eight and nine all of them are empty okay and even more the method on which we're opening that page is get okay that's why the whole post is empty okay and we can dump the whole post and have a look right here dump the whole post i'm gonna exit right here as well refresh and this is our post okay so what do we need to do we need to check if the request method was posed then we need to take the data from the post how to check what is the current request method is it a post or is it a get we have to use super global server so i'm going to dump the server right now and exit so let's have a look this is our server and if we observe this server contains a lot of information okay it contains the mysql home directory php version uh the current user agent which browser we are using and many many other information okay the operating system information and so on what we need to do right here is method so let's search for method and here we have request method and this indicates that the method is get so if i just remove exit right here and refresh so the method is get we don't see anything right here simply because we have some fatal errors okay but if we submit that form the request method will be post okay so we need to do something like this so if super global servers request method equals to post only in this case take the title description price from the post and make an insert in the database okay we need to do this only if the request method is post so now if we open that form and remove that server variable if we open that form we don't see any error okay so if i open that form it looks good and it also doesn't make any records in the database because this is written inside an if statement and the request method is get in this case but let's just print the request method okay server request method right here let's put here as well and let's just submit the form so title description price hit the enter and here we see that now request method is post and in the database we should also see one more record and here we have title description and the price okay so this works also very well we need to make validations also so if the title or price is not provided we have to print the error okay so how to do that so we need we can just easily check if the title is not does not exist basically if the title is an empty string it is a falsible value okay and if uh the title is an empty string that if we'll be satisfied because we have a not right here okay so if the title is empty string and we just write if title so this if won't be satisfied if i put right here not in this case it will be satisfied so if the title is an empty string in this case we need to write some error okay so like the product title is required okay and we need to do the same thing for price so we can have several errors and right now i'm going to create errors array okay and whenever i have that errors i'm going to display that errors array at the top of the form right here okay so right here i'm gonna put a bootstrap alert okay that should be div with alert class alert danger okay and i'm going to iterate over errors php for each errors as error and i'm going to end for each use the end for each syntax php end for each and i'm going to display right here a div with the error message okay just like this one so let's just write here if title is not provided errors inside the errors let's just push please provide the product title or just product title is required okay and we need to do the same thing for price so if price is not provided inside the errors let's just push product price is required okay let's just save this and submit the empty form so we open that empty form and here we have another error that happens on line 50. that happens because right here we are using errors but it is not actually described okay so we have that error description describing the error inside if statement if the request method is post so we just need to put this at the very top so i can write these things immediately at the very top but i want to show you the problems beginners come across and then how to solve these problems okay so just i knew when i wrote errors right here that there would be an error down below but i just want to make mistakes and then fix them okay so we have errors right here and let's just remove this uh request method we don't need we understood how to print the request method now if we have a look okay we don't see the error but we see that empty red background area which is not good right and we see this because we are always displaying the alert even though the errors array is empty okay so we can write an if statement if errors is empty and we can use empty method for that if errors is not empty more correctly if errors is not empty display the following alert and down below we need end if okay just like we are using and for each we can use and if if we are using that column syntax okay save refresh and looks good okay when we open the form we don't see anything extra now if i hit the submit button i see both of the errors product title is required product price is required and but still the record is made in the database because we have not actually wrote written the corresponding code okay so when we set errors right here we need to check if errors is empty only in this case make an insert in the database okay so if errors is empty let's just use the empty function only in this case make an insert in the database and now if i just hit the submit button and have a look in the database it doesn't make inserts in the database okay perfect if i provide something in the title okay test product and hit the submit button i see one error only about product price okay and it also does not make recording the database which is very good which is exactly what we want okay so if i provide both like the product title and product price it will uh it will make an insert in the database but one important thing as well so if i just don't provide the product price and hit the submit the product price which i uh the product title which i entered right here simply disappears okay so we need management for that as well okay so we just want the title to be displayed right here so how to do that so we have title description and price variables right here so if we can just use them right down below when we render the form and assign the value back so if i just write value equals php echo title so let's just write title back inside that product height okay so if i refresh this right here i see that product title is displayed but this code has some error so it is not very good solution doing just like this and i'm gonna pause right here for several seconds think about it what problem this might have and then see my solution okay the problem is that if i just open that form using method get i see that our undefined variable title because again the title is described inside that if statement and we are accessing right here when it is not actually described yet so we're doing to do is that let's create a variable title with an empty string right here okay and that should fix the problem okay we don't see this anymore and let's do the same thing for price as an empty string and for description okay now let's just use that price and description down below as well so inside the text area we're gonna display description and down below inside the price we're gonna display the price okay now if i provide price but don't provide the title hit the submit button i still see that price is provided and if i just provide also some description and hit the submit button both of them stays there it only complains about the title okay so the validations are also done which is very good now what we need to do is to upload the file okay so how to do it so let's choose one file so let's go to the pictures php course and i'm going to choose right here that image and hit that submit button but of course it won't do anything because we don't handle uploading an image okay so now it's time to introduce a one more super super global variable which is called files okay super global variable files contains all the uploaded files so i'm going to exit right here stop execution for the rest of the code and let's just have a look at the files so also one important notice so if i just submit that form my files will be empty in order to be able to upload the files we need to add an attribute to that form okay and that attribute should be ink type multipart form data okay using this basically i'm telling the form that i'm gonna submit files okay so let's open the create form let's actually uh comment that yet open the form i'm going to choose the file and then i'm going to uncomment this and hit the submit and here we see the uploaded file okay it has key of file image and that key basically is what we gave in the form right here okay this is the key and the value is an array of uh key value peers it's an associative array this is the original name of the of the image we uploaded this is the mime type this is the tmp name and this tmp name is basically what we need to use so whenever you upload a file apache saves this in the temporary directory okay and this is where apache saved that uploaded file so you have one request to move that file into a permanent permanent storage permanent folder and then the file will be deleted okay so right now in this request when we upload the file we have to take from the temp name and move it somewhere else okay and that means that we successfully uploaded that file okay and this is the file size so whenever we move this somewhere we have to also put in the database the location of the image so that we can use that location when rendering products in the list okay so how to do that we need to also associate somehow that this image is connected to a vet product not only uh in the database level in the column but on the file system level as well so let's start with very easy steps and let's just directly move that uploaded file to somewhere okay so for example if there are no errors if we hold if we don't have any errors about the title and uh price let's just put right here uh uploading an image okay so first we need to check if the image was actually uploaded it is an optional and it might not be uploaded right so we get image from super global files for key image okay but if that image is not presented in the super global files let's just take the image to be now okay then we need to check if the image is not null if the image exists so we have to save that image somewhere okay so for this i'm going to use move uploaded file function we have to specify from where we want to move that uploaded file and this is gonna be the path okay so it's gonna be the image tmp name okay the tnp name so from image tmp name we want to move it somewhere else so for now i'm just gonna move it into test.png okay or jpg let's let's just make it jpg because it is actually jpg okay so this is how i'm gonna do this and i'm gonna exit right here okay i don't want uh the record to be inserted in the database i just want the uploaded file to be saved on the file system okay so let's just save this and refresh we have exit above so i'm going to remove it exit refresh and let's have a look on the left right here we should see that uploaded image but we don't see for some reason because the errors is not empty okay so because errors is not empty we just don't see so let's just provide title and surprise hit the submit let's just choose the file also hit the submit and right here we see that test.jpg and that is the file we just uploaded okay so perfect now what we can do is that put write that information test.png in the database but this is not perfect you know why because two products might have uploaded files with the same name okay and the latest one will overwrite this one okay so when we upload the file we need to make sure that the path of that file should be unique for that product and won't be the same for another one or it will just overwrite okay this is another mistake many beginner developers actually make so they just upload that file so we can even do like this so this is the product and this is the actual name of the image we are uploading so instead of putting this in test png many beginners put this in its own original name like the or image name okay save it and whenever i refresh that form it's uploaded on the following with the following name okay and that should actually belong to that specific product what we are creating right now but the thing is that if we just create another product and upload the same image the second uploading will overwrite this one okay which is not very good okay which is not correct i would say so we have to make sure that we save that image in a unique path for that product so one solution is to wait until we save that product in the database take that product id okay create a folder and give it an id as a name of the folder and put the image inside that folder so we are sure that every product has a unique id and we will have unique folders for that product and we can have each image of that product inside that folder or we can even call our image the product id dot png or dot jpg whatever it will be but in this case we have to wait until that product is saved take the id save that on the file system and then we have to also update the image inside the database because in the database we need to write what is the actual path of that product okay so that to get that later so another common behavior is to generate a random name folder and put the image inside that random name folder okay so how to actually do this so we need to create a function basically for generating a random string okay so let's do the following approach okay so i'm actually going to copy and paste that function so and i'm going to explain of course so i'm going to paste that function right here random string and let's have a look so we have characters right here from 0 to 9 from a to z and from uppercase a to uppercase z okay and we want to generate random string out of these characters and we pass in as a length of that string okay i want to generate in length random string so what do we do so we iterate from 0 to n and we call a random function rand function from 0 to the length of that string okay so the rand function accepts minimum and maximum okay this is the maximum and creates uh generates a random number for in in between these interval like the minimum and the maximum and we are sure that when we run this random with zero and str length of characters minus one it will pick an index uh from zero to the length of the string okay and then we take the actual character from the characters based on the index okay so if random index will be i don't know whatever is the index of the c then c character will be picked up and it will be concatenated to the string str variable and save back inside the str then another random character will be picked up for example the uppercase c and it will be concatenated to the c itself and so on okay and using this approach we actually have possibility to generate a random string with the given length so i'm going to use that random string right here above okay before actually calling that move uploaded file okay so right here we're gonna write to how to make an actual uh like the random directory so i'm gonna do like this i'm gonna make all images inside an images folder right here okay just don't create the random directories immediately right here okay but create an images folder so to have them all together okay so i'm gonna write if image is uploaded then or we can do this even out there so right here so if the directory doesn't exist images directory okay if that doesn't exist i'm going to put not right here then create images directory okay so whenever the following code is executed the very first time actually so right here we don't have that images folder it will create that images folder okay okay very well so now down below we have to actually uh create that random directory so how to do that and we have to also create the image path so image path will be so where the actual image should be saved and that's going to be images inside the images folder random string for the length of 8 and then we're gonna provide the actual uploaded image name okay that's going to be the image path and let's just dump the following image path and have a look and i'm going to exit right here save and refresh and here we see that image path so inside images folder inside that random directory this is going to be the image okay if i refresh this i see that random directory actually changes okay right here so we are sure that this will be unique so it's there's very small chance to create to generate two random strings of length eight with the same um like the sequence of the characters okay there's very small chance for that so we are creating a unique path for that image okay and that image path can be used down below when making insert in the database okay so i'm going to specify image path right here however that image path is also created inside the if statement right here okay and if the image is not uploaded on the following line we're going to see an error that the image path does not exist so let's just create that image path right here equals to an empty string okay now i'm going to create a folder with this random string path and then upload image inside so i'm going to use mkdir again and specify right here dear name function so the dname function accepts the file path and returns the directory where that file path is located so i'm going to specify image path which is the following image and it will return the following path so we have to create directory with the following path and when we do this we can already run the move uploaded file but right here we need to specify actual image path where we want to upload that image and save that and refresh and have a look so something um is actually wrong no nothing is wrong let's have a look in the database refresh it and right here we see that image okay so this is the product and here we have that image and if we have a look in the file system on the left side we see images folder inside images folder we see that random name and inside that random name we see that image which we just uploaded okay so i'm gonna delete that files okay and that is basically all about creating a creating product okay the last thing what we need to do is to redirect user to the index page when the product is actually created okay so for this i'm gonna use header function and i'm going to specify the header which basically points to redirect so location header corresponds to index.php okay let's just redirect user to the index.php and save that and go to the product squad let's just remove it files we don't need that and let's just create one product okay galaxy note 20 okay with some description with optional description with some price okay and let's choose image as well and hit the submit and we we are redirected to the index page and we see galaxy note 20 right here if we have a look in the database we see that it has also image however if i create one product without an image we should not see that okay so refresh right here and here we have another problem so we basically see that images slash and the folder so which is not correct so we have a problem we need to fix that okay and this actually happens because that image was actually existed okay so if i dump that image right here okay and exit immediately okay let's go to the products page and create test product with price hit the enter and this is our image so even though we didn't choose image it still exists with everything empty but it still exists so we need to check right here if image exists and the image also has tmp name in this case let's run the following code okay so let's just remove this for dump and refresh it let's have a look in the database and the last product doesn't have image at all okay perfect now it's time to implement outputting image right here okay so let's go to the index.php scroll down and right here we need to output that image okay so it's very easy now we have to create image tag with the source and right here we have to output product image okay just like this save and refresh and here we see that huge image which we should not see of course that huge so i'm going to open up css actually i'm going to give also that image class image tag some class okay so let's give it a class of like the thumb thumb image okay so let's go to the up css and give it a width of 50 pixel okay save it and refresh and probably we need to clear cache and refresh like that right click empty cache and hard reload and here we see that product images okay for this one this is broken because it just has a folder it doesn't have an actual image okay so now it's time to implement delete and then update okay but first let's do delete because it's easier and we can clean up some products okay so how to do that let's go to the index.php and whenever we click that delete button it should redirect us to the delete.php so i'm going to change this into an anchor link inside href i'm going gonna provide delete dot php and i'm gonna pass the id of the product which i want to delete okay and i'm gonna pass this as a qr string okay id corresponds to product id okay now if i refresh and click the delete i see in the url delete php id equals 13. if i click this on another product i see id equals 11. so we have to create that delete php so let's go to the product script right click and let's just create delete php and we have to get that id from the get super global get select the product and delete or just don't select immediately delete okay so let's take out the id so id equals from super global git let's just take id okay but here's one important thing also which to which needs to be considered okay the id might not be given okay so we might access these we have possibility for that we might access this without the qr string in this case we have an error undefined index id so what we need to do right here if that get id exists then take that id otherwise take now okay and we need to check if id does not exist if not id then redirect user to the index.php okay location index.php and that's it we can put exit right here as well okay refresh and we are redirected to linuxphp which is good okay now we can actually implement and delete that product based on the id but i'm going to show you one thing which is also good to consider okay so because when we click that button it makes changing the database it actually deletes a record in the database it's better to do this using method post okay how to do that so in the index.php i'm gonna revert this back into button okay and i'm gonna put this button inside form okay and inside that form i'm gonna create also one input which will be input type hidden which will have name of id and the value of the product id okay so and that pattern basically does not need href anymore and its type should be note button but submit okay so whenever i click that button it should submit that form with method of post and it should submit that on delete php and it will send that id as a post value okay so now if i create that delete php and take that id from post instead of get and just dump this id right here we will see that id okay so refresh so by the way these buttons are now not next to each other but they are stacked so this is because the form is a block level element so we have to specify right here that its display is inline block and that's it so we will see them next to each other so i click the delete and i see that id taken from the post and and i don't see that id also in the url okay now we need to connect to the database and delete that product okay so i'm going to copy the connection string okay again i'm highlighting that we are doing this not in an optimal way we are just focused on to achieve our purpose as as quickly as possible just i'm trying to teach you as much as i can okay and then we're to change this and make this improved version and we're going to learn also some new techniques so in the delete php i'm going to paste this and we have to actually make uh delete we we have to actually create prepared statement down below okay if id exists okay in this case we have to run prepare that should be delete from products where id equals column id okay we have to save that statement oops statement and we have to bind bind value okay so this is the column id so we have to bind column id corresponds to id and we have to run execute on that if it's we if it is not able to update that to delete that product it will throw an exception however if it didn't throw an exception it successfully deleted and we're going to redirect user to the index php save it go to the product index page and i'm going to hit the delete button right here and you see that the product is deleted okay so let's just delete unnecessary ones cool we can also check the database that we don't have that much recourse here we have we have only six records now okay so we successfully implemented delete now it's time to implement update okay so let's go to the index php and i'm going to change this into anchor link i'm going to add right there update dot php question mark id equals to the product id okay we are not going to use form and button just like we did for the delete because that just opens the form that does not run the actual update okay so it should be anchor link with update we pass the id we don't need that button okay and that's it so we don't have of course that update php so if i just click the edit it will show this not found so let's go ahead and create that update.php and we need to copy and paste couple of logics right here okay so we have to actually render the same form we are rendering in the create php right so but if if it is an update we have to also display the user uh not the user sorry but the image okay of the product so let's copy and paste this on update and let's make a couple of adjustments first of all right here at the top we get the id okay and if we didn't get the id we need to redirect user to the index.php so i'm going to copy the following logic and paste right here and i'm going to take out now this from get not from post okay and if we didn't provide id it will redirect to the to the index.php now we have to select the product based on that id okay so we create statement equals pdo prepare select everything from products where id equals column id okay on statement we bind value this is going to be the id id right here and then i'm going to call execute and then i'm going to call fetch and not fetch all just fetch and specify pdo fetch associative area and that's going to be the product i want okay and i'm going to dump this product right now and exit don't continue execution refresh and here we see that product we would like to update so if i provide another id right here but let's just pick up the existing id like the first one for example okay that's going to be iphone 11 we have second id that's going to be galaxy s20 and so on now we have to populate form with the values and we should also display the actual image okay so we need to do that let's go to the update php and scroll down so the following code is executed when the method is post so it's not going to be executed when we open that form so let's just collapse this for now we have that random string function so let's just leave this as it is scroll down and right here we have the errors and probably inside the form right here let's just display the image okay so we do the following if the product selected product has image there let's just display it okay and if and right here i'm gonna display an image with the product image okay excellent let's have a look so how this works so this product doesn't have image let's go actually back so i'm going to create a big link button from the update php so right here not actually let's do a path so let's make a paragraph inside the paragraph i'm going to make an anchor link with href to index.php go back to products okay let's see that should be probably btn btn btn secondary refresh and here we have it okay let's click the edit on on the product which has image so here i click edit and i see that huge image so i'm going to add a class on that image as well right here let's give it a class of update image i'm not going to give it a thumb image because it will be very small so let's make it update image let's go to the up css and paste update image right here and let's give it a width of 120 pixels okay refresh and this is our product image okay if i want to change that product image i have to choose another one okay but the actual product title product description and product price is not populated okay let's scroll up inside that update php and we have that product title price and description and what we can do is that just select take the title price and description from that product because it is an associative area okay so product price and product description okay save and refresh and here we see so it is there uh probably the description is not provided for that special product that should not be called by the way create new product that should be called update product in the product title update product and let's just make it a product title so this is good and okay now let's implement the actual updating of the product okay so almost all validations what we have implemented for create will be the same so we did we take the uh the title description price so we we don't need the date by the way so we we should remove this and if the title and the price is not provided we run the um the add the errors and then this can be there so on the product the creating that doesn't hurt anybody so if we can leave it and if the errors is empty then we take the image but what we need to do here is that we need to first delete the old image so that specific product might already have some image okay so we need to delete that and i'm going to write an if statement here if the product we selected at the top has some image let's go ahead and delete that image okay product image unlink basically removes that image okay and we can even remove the whole directory okay but i'm going to leave this for you as it is now okay the rest of the code is the same so we just uh if the image is uploaded then we just uh make the saving that in the database but instead of inserting here we need to run update okay so let's just run update products and we're gonna set title to equal to bind parameter title okay image equals to bind parameter image and let's move this on the next line okay the description equals to description price equals to buying parameter price and we don't do anything with date because it is already inserted there so the date is inserted basically when we create record not we update okay so update product set title image description price and then we provide these values like the title image description uh price and we don't need date and we also need to pay attention to the image path okay so that actually should be if we don't upload the image that image path should not be an empty string but it should be actual product image okay that should be the image path now let's see how this actually works so refresh this and maybe provide some description description for note 20 and hit the submit button and something bad just happened okay i see what happened that's the biggest mistake so right here we run update without wear so which basically means that we update all updated all the products with the same title image description and price so we have to specify right here where id equals to the column id and that id should be bound right here okay id is the id okay so here is our mistake so let's now refresh and edit and let's choose a different image and it should be galaxy s20 okay let's remove this we can leave the price so and it was actually updated let's change the other ones into iphone for example iphone 11 hit submit and it was actually updated we can put something in the description description for iphone 11 and everything basically works smoothly but right here it didn't work so when we update the description but don't do anything with the image it actually did not work and let's see why so if i just inspect that and right here we have this tk6 so there should be an image inside the tk6 tk6 no we don't have image right there okay so let's see what happens aha so here is the thing so we delete the product image if there is that image we basically don't check that the image product should only be deleted when the new image is uploaded okay so that should be written inside that if statement so if the new image is uploaded in this case we should delete the old one and update the new one okay so save and edit that iphone hit the submit okay and the others were broken and that why did that happen so let's just have a look so it should be which one is this let's note 20 so let's update the node 20 hit the submit and it is there and for that others there is no image so that is actually good so we can delete that others okay so this looks good so we have successfully implemented creating updating and deleting of products with the easiest possible way we could okay so now let's do a quick search so how to do it inside index.php i'm going to put right here above the table form group so let's go to the bootstrap documentation and i'm going to search for input right here and i actually want input group so down below i should see that input group example right here so this one recipient's username so i'm going to copy this and paste right here and inside the placeholder i'm going to write search for products okay this search basically needs name as well let's remove this area so it needs name to be search and it also should have button which will be search okay and we can put this inside form as well which has type of submit okay and we can put this inside the form which will submit on the current file index.php with the method get so i'm going to leave that attributes action and method empty paste this right here and let's actually see so right here refresh here we have that search for products i'm going to write something right here galaxy hit the enter in the url we see search equals galaxy we can take that using get right here okay so search keywords search for example equals to from the getsuperglobal i want to take out the search okay if search is not presented there let's take out an empty string and i'm going to write an if so if search exists then we make we need to make slightly different select okay if search is not there then the select remains the same so select everything from products if search is there i'm gonna add right here where title like the bind parameter title okay and if we pass right here bind parameter we need to bind the value as well statement bind value for title it should be the search text okay but i'm going to put person symbol in front of and the after the search that is necessary for mysql like to search in the middle of the title so i save that and refresh and you see that it filters only that galaxy okay so if i provide right here iphone it searches that iphone only but we need to put that search keyword back inside the input so how to do that we have that search right here and we can scroll down and assign a value to that input so right here i'm going to write value php echo search so whenever we open that we have iphone right here if i just remove that qr string and hit the enter that search will be an empty string and it shows every product okay so let's add one more product iphone iphone se for example some cool description in the price we provide something in the images we provide that se image hit the submit and right here we see that at the very top so if i update that i can change this image submit and here we see okay so everything basically works fine however we should mention that we did not write very optimal code so i'm not proud what what we did so we achieved our result so but we should always think how to write reusable code how to achieve our goals in the best possible way so as i mentioned very often beginners choose the following way and i just followed that path so created four different files for index update delete and create we have the connection to the database in all these files uh okay and we have some similar logic in these files and we also have the layout that talk type doctype.html and header everything basically in these three files index update and create the delete basically does not need that layout because it is redirected back to the index.php okay now it's time we have to modify our uh our code so that we can make it better so this is working but this is a bad version of that crot so now we can make it better and learn let's learn uh how to auto load files learn how to work with composer and then we can rewrite this in the best possible way okay so let's refactor release so let's start with the partials okay scroll down in the update or index.php and we're gonna move this into a separate file okay so i'm gonna create on the left side so actually i'm gonna move everything this okay in a folder called uh zero one uh underscore page so this is the base version and but i'm gonna provide this on on github so you can see the what's the page version okay so let's move every file inside that bit and let's create now a second folder which will be better and then we're gonna have good version okay second folder and that's going to be better and then we're going to have good version as i mentioned but even that good version won't be the best version so i will call the best version the version which includes all the modern and tested tools like if you want to create a real application which includes even the crowds application uh you should think more about like the pagination and couple of other things like the grouping items and so on and the best version from my point of view will be a version which will be based on some modern popular framework like laravel or e2 framework okay so let's actually refactor this in a like the best possible way so how to do that so first of all we need to create a one folder for uh views let's do that views okay inside that views we're going to create also one folder for partials okay and inside the partials i'm going to put the header in the footer okay so let's take that and make it as a header so inside the partials let's create a file header php and i'm going to paste this right here okay and let's just include that include include ones that views so this is the update okay so this is a this is a different file so let's actually copy and paste this code so let's let's return this back so this is the um this is the paid version so i'm going to close all the files right now and move them one by one into my better folder okay so let's move this update into better folder okay so right here so and inside the updates we need to change that header php include include once it should be include ones views partials header and let's do the same thing for index and create so i'm going to copy and paste this index and create right here and let's copy this header inclusion and go to the index.php and paste right here into update php we already have into create php and paste right here okay and we can do the same thing for footer but it's much much smaller code it's just body and html so you get the idea so i'm going to leave this as it is let's more focus on the code reusability for example connecting to the database okay so these two lines are repeated in these three files and two lines might not be very big problem to repeat but the more bigger problem is that we actually have that connecting credentials in three different places so if i decide to change my database from db name from product scroll to just products i have to update this in three different places okay which is not very good so in the best case i should have this in a single place so i'm going to create uh inside that better folder i'm going to create database php okay and i'm going to move this code into the database php right here okay and i'm going to use the database php right here but i'm not going to write include i'm going to write require once okay and we need that database php and i'm going to repeat that for create and for update but look at this phpstorm cannot see that pdo variable so it doesn't understand that the database creates pdo variable okay so that's actually fine it will work and we can have a look in the browser as well so let's open that better version and right here we see of course images are broken and we're going to fix this step by step but the connecting to the database actually works okay and the keywords are successfully made so if you want that to see if you are using phpstorm and you want that to be seen by php store we can do like this from the database php we can return that pdo okay and right here we can assign that pdo variable okay in this case phpstorm can understand that here's a variable of pdo however it cannot understand what is the type of that pdo okay so we can do in a different way and we can revert this back from here as well oops not this one and we can declare right here a doc block okay so right here i write a variable of pdo is an instance of pdo class okay and in this case phpstorm can understand that the variable exists but it can also understand that the variable is an instance of the pdo so if i just start typing some methods like the prepare it autocompletes that for me so if i just remove this it doesn't see it doesn't autocomplete also okay i'm going to copy and paste these into the all three files okay and that's actually good and let's now work more and about like the combining create and update um forms into single one because we have that forms in a separate files and if i decide that i want to add one additional input field right here for example the product location okay i have to do this in the update php and in the create php as well okay i want this to be in a separate place in a separate area which can be reusable okay so inside that views i'm gonna create a folder for products so if we think about that we're gonna probably if we think that this project might get large and we might have other crowds right here we need to put this in a separate folder okay again i really encourage you that if you are doing big project and if your project gets larger i really encourage you to use the modern frameworks like laravel or codigniter or e2 or symfony okay and there are others as well and don't start implementing uh your things so implementing your own framework or like the cms is good for learning purposes okay and for some side projects not for projects which needs to be random production okay and right here i'm going to create a form okay let's call it underscore form or just form okay and inside that form i'm going to move the actual form and probably that includes that errors as well okay so let's take out the following code and move it inside that form okay but we need couple of variables right here we need product variable we need errors variable okay and the form should be used in update php and in create as well okay php include that views products form php and let's move copy and paste these into create as well so let's just remove all this form and errors and paste this right here okay however our form has a product variable right here and checks if that product variable exists it takes that image from the product variable and renders that image okay if the image exists on the product so let's see how this everything works so if i just click that create product so i see the following error undefined variable product okay so this happens because inside createp inside create.php we don't actually have that product variable so what i'm going to do is that create that product variable okay inside create php to have title as an empty string in this case we only need image so we can just do it with the image okay so let's let's do first with the image refresh this and the error basically disappears okay so let's have a look in the console because i think up css is not included and here we have it so up css is not included let's move copy up css from bed into better version and here we have refresh and that looks good okay what else do we need to do inside create create php we have that function random string and we have the same function in the update.php we should not have like the repeated code so right now i'm going to create a file which is called functions.php and i'm going to move that the following function there inside that functions uh right here and i'm going to include that functions php inside update and create as well so i'm going to remove that function from update and at the very top i'm going to include require once that functions php and do the same thing inside create okay require ones functions php save and refresh so let's now see how this actually works by the way we need to add right here also go back to products so let me copy the following pattern so go back to products and put it in the create as well right here refresh go back to products this works fine by the way images are not also displayed so let's copy these images right here okay we have a lot of empty folders that's probably we don't delete the folder when we just delete the image so let's just refresh and here we have all these things and let's see update so this is the update which works fine so let's just add update it hit the enter and it works fine let's just create new product new test product with some price hit the enter and the new test product is also there however we still have code duplication and that is inside that create php and update php okay so most of the logic of validation right here or uploading an image is the same okay so we are taking just the if the request is uh method is the post we just take the title description price we run some validations if the directory doesn't exist we create the directory and then we upload the image okay so it will be good if we somehow be able to combine them into single logic okay so i'm going to create a file and i'm going to call that file validate product okay and i'm gonna move most of the logic from update and create into that validate product that's gonna be take the title making the validations saving that image okay everything this except actually making some changes in the database so let me copy this uh paste right here and remove that making changes in the database okay also redirect so let's format the code and right here we have the title description price we run the validation and we need a product right here which will be passed from the update okay and from the create so if i just remove now the following logic okay so this is by the way updating an image okay so just remove this thing from here okay remove that validations and title as well and i'm to include or require ones that validate product okay so we have that validate product right here and that validate product basically creates a couple of variables like title description and price but we need also image path so that image path should be also created inside the validate product okay and then that image path should be used down below right here as well and now if we have a look at this so we don't have that much information right here okay so uh let's observe the code okay so if the method is not post if it is a get so we get the title price and description from the selected product from the database and we display this inside that form okay we pass that title price and description but we also pass product which is necessary for rendering an image right here okay so if the method is post we get that validate product that validate product takes the information from the post creates variables there runs some validations and if there is no error basically about that validation it also makes an uploading saving of a file so right here we see that the if the errors is empty and if there are no errors basically from that validate product file we run the update okay that should actually work so let's just save this and go to the website and edit that and add an image for example okay new test product upload an image and we see that right here so let's give it also some description hit the submit button then edit and we see the description is populated right there so the update script works perfectly let's now see how the create script works so click that button and inside create basically we didn't move any logic right so we just need to remove these things and we also need the date inside the create so what we can do that is that pass that date down below immediately okay right here instead of having a variable okay so let's just remove the title description price the validation creating directory also remove that uploading a file because that is all done in that validate product and let's just write require once validate product okay and if the errors are empty then we make an insert in the database okay so let's see how this works now so go to the products page and choose a file test product 2. i'm going to leave the description empty price one two three four hit the submit and we see right here that the product is actually added okay so if we go inside the edit the description is not there so just add test so everything basically looks good okay so and if we just analyze the files we have reduced the code written a lot okay so let's have a look in the update so what we have written here is that we include the database connection and some functions and we just do the validations that that if the id is not passed we redirect user to the index.php then we select that product specific product from the database then we check some validations which is um inside the validate product and we just directly make an update in the products and down below we also have much smaller code we don't have everything so there are only 54 lines okay in the create php we have something similar okay we don't have that much code repetition in the functions php we have moved that random string and in the where is the delete php okay we don't have the delete let's move that delete php which i think doesn't need anything to be changed so yeah we need to put right here i require ones of the database so i'm going to copy these two lines and paste right here and that is delete php let's have a look if the delete works so i'm gonna delete that product and here it is so it also works fine however this is not perfect version okay so we have to make a couple of changes right here also so first of all if we just have a look right here inside the index.php we can actually access database.php okay we can also access functions.php invalidate product.php okay and the database php basically doesn't do anything wrong but it's a very bad practice to access the files from the browser which are not necessary and which should not be accessible from the browser okay and we should move only in a specific folder only the files which should be web accessible so very often there exists in a modern frameworks there exists a public folder and that public folder is only web accessible folder public or it might be called also web and in this case we're gonna move the create index update and delete as only web accessible php files inside that public folder okay i'm gonna cut them and also inside public i'm going to create a folder for products because in the real applications there might be some other crud like not only for products but it might be for orders okay so right here we're gonna paste this and they are moved inside that public products okay however we need to adjust how we are requiring okay we need to go one directory back no two directory back and fix that require once in all these files okay let's open index.php as well and in update as well okay and we have to also adjust the views okay if we scroll down right here we first of all we need to adjust that validate product and if we scroll down right here we need to adjust views as well okay let's do the same thing in create right here as well so let's save this and have a look right now so we open that better and we need to go to the public and products okay so we have a problem in the index.php the partials included basically right here needs to be fixed refresh okay and the up css there's a problem about up css okay so when we develop a real application it is very often and it should it's a good practice also to be started on a virtual host okay so we create a virtual host and we run application on that virtual host so the virtual host might be called for example products.test okay and whenever we open that url it will basically display the same application what we see right here right now so a simulation of virtual host will be php's built-in server okay so i'm going to open terminal right now go to that folder 14 in a better and in a public and that public is the only web accessible folder as i mentioned and we're going to start a php's built-in server using php minus s localhost localhost port 8080 okay i'm going to hit the enter and that starts that php development server and let's open port 8018 and we don't actually see anything because it searches for index.php okay so let's open index dot php but there is no index.php in that public right index.php is inside that products so let's just open products slash index.php i'm going to hit the enter and right here we see all the products and basically it will work in the same way as it was working before however we need to fix the css and images problem okay refresh this and we see how the css is included so it is included from the product slash up css we need to change that and we need to include that using uh slash as an absolute path so let me show this to you okay so right here if we just put slash the css basically will start working but we need to move that css into public folder as well okay save it refresh that and the css actually started working so we see padding around that content okay so if we just don't create a virtual host or don't start that php's built-in server we have to struggle a lot to detect what should be the current path for the css okay so right now if we just have a look that up css is included from uh slash localhost so because we put right here slash that's is taking from the domain okay domain slash whatever is the domain slash app.css if we just don't have these in this case the css is included from that public product sub css okay so in this case we have to go one directory back and do something like this okay which is not safe okay not very good solution so here is the problems that beginners come across when developing on php okay so no our bed version neither better version is good enough to actually um like the be proud of what we've done okay so we need to like have an absolutely different approach okay and this approach even is not perfect it's not not even close to perfect because if we have another crowd applications like the orders and the um like the invoices and so on and so forth so we have to create each file for each operation like the create update delete and finally we may come up to hundreds of files uh just for that no like the functionalities okay and it will be very hard to maintain and it's not also like the good practice so even though we made this better and we have that web accessible folder and we have that views and separate files and so on it is not like the best approach okay i'm going to show you a couple of things right here when like they finalize that the better version and then we're gonna move uh the next topic okay so let's see so we we cannot continue working on this url anymore we should should switch to that okay that is more safe and more correct okay and later we can also create virtual host out of that so now we're gonna put uh right here slash up css that is from which we need to actually include refresh and we see that and we need to adjust also images okay so whenever we include images we need to put slash in front of that first of all let's move all the images inside the public folder okay that's that's good okay why are they opened i don't know refresh we don't see that images and let's go to the index.php inside the products index.php and right here we need to when we display the image we need to put slash in front of the source okay we put slash we refresh and we see all the images okay if we go inside update we need to put slash right here as well so let's go to the form php because we have the update right here and we put slash right here okay save and refresh and this image is also displayed however now if we upload an image it will be uploaded in a different folder and let's observe this i'm going to close this pad and let's actually delete all the empty folders okay and now let's upload an image so let's create actually new product okay test three i'm going to upload the image give it a price hit the submit and here we have that problem validate products that's another problem by the way let's go to the create php and right here we should adjust that inclusion so refresh that and the product is created however the image is not displayed okay why does this happen so let's observe actually so right here look at this so the image was actually uploaded in the images folder of that products so we didn't have that images folder like before here but it appeared okay so why does this happen okay so if i just delete this i'm going to show you this once again so if i just delete this and create one more product with some test and some values hit the submit right here it creates that images folder okay so this happens from the validate product okay so the image is uploaded from here and look at this what now happens so right here when we actually move uploaded file okay or just make directory or basically when we do some operations with the file system and we just specify a relative path in this case image path is relative it doesn't start with slash so this means it is a relative path so that relative path is taken from relatively from the file which is executed right now and when we create a product create php is the file which is executed okay so right here and the create php includes that validate product so any path basically which is right here given to a function which works with the file system any path basically is relative to the current file which is executed okay and the current file which is executed is the create php in the product in the public products folder okay and that's why because every path is relative to that create php it creates images folder next to the that create php and it also will delete that image okay however we don't want it to be like this we want that to be saved inside the images so that's also a good thing to learn something new okay so now let's actually use a magic constant tier so that magic constant deer refers to the current directory where that file is located and that file which is called validate product is located in the better folder okay so what we need to do is that no matter if we are creating an images directory right here or doing something else regarding file system we have to prefix from the current directory okay from the current directory let's go to public and images so if the directory inside public images doesn't exist let's go ahead and create that public images directory okay down below when we need to delete the product image from the current directory we go to public folder and inside the public folder we delete that product image okay right here when we actually need to like the create directory i'm going to prefix the public folder and then the image path okay and right here also when we need to save in the database i'm going to prefix not in the database but on the file system i'm going to prefix public and then the image path okay so this is how we need to do and now if i just remove that products images which should not be there and if i create new product test 4 choose an image hit the submit we see the image right here and that image is uploaded in this folder okay so that we see image right here proves that information okay so as for the searching i think search works uh as it was working before like it searches all all the test products or iphone or anything what we want okay again i want to like highlight that this is not a good version it's better definitely than the previous one but it's not going good enough version like to be proud of what we've done okay so we need a different approach we need a different mechanism just i wanted to build that big and better version so that we know how to like refactor our code how to like split into different files and how to work with problems which generally come across and because this is the crash course this is for absolute beginners we need that knowledge so we need to write bit code to learn how to improve that code and how to like the meta make our code better and we need to also see what's the difference between the bet code and the good code okay so we need to know that this code is not good it is actually paid code and probably these such kind of codes are the reason why many people actually don't like php okay because such kind of codes are very often written for production websites especially in an old time okay so now let's move on about autoloading and see how we can use composer for autoloading classes and then we're going to rewrite our products crowd application using custom routing we're going to come up to custom mvc routing and mini mvc framework and build the product scrolled on top of that and we will see a huge huge difference between that product scroll what we have right here uh better or paid and those that one we're going to build after the we learn the autoloading okay so let's do this let's first talk about namespaces what are namespaces and why are they necessary so let's imagine that we're building an e-commerce application and we need the following classes in our project we need class email class person and class order okay and we decided to implement the email sending and for this we need to install third party package in our application and that third party package also has class email in its source code so we have a name collision between our email class and the email class that third party package provides so what is the solution basically using this approach there is no solution until we rename our email class to something else but namespaces is the perfect solution for that so in general it's good practice to put all our source code in a namespace called up or whatever namespace you prefer so in our case if we put all our classes in namespace up the identifier of the class is not just email person and order but it is up backslash email up backslash person and up backslash order and if we just try to install the third party package in our application which has class email it won't conflict our email class because our email class is in different name space and it is it's a full identifier is up backslash email it is much like a files and folder so namespace can be a folder and class name can be a file you cannot simply have two files with the same name in a single folder right okay now let's install composer and enable autoloading and in general see what is autoloading and what advantages it has in order to make autoloading working we need to have composer installed okay let's type composer in google and the very first link will be what we are looking for we're going to hit download and we just need to download for our operating system for windows we're going to click the composer setup xa for other operating systems and for command line instructions we just need to copy and paste the following in our terminal so i'm going to click composer setup for windows and it's going to start download and download it for in couple of seconds right here we have it i'm gonna click on composer setup and let's just install this i'm gonna install for all users yes next we're gonna leave this default next next and install okay so installation is basically done and now we are we are able to use the composer command from command line okay so let's just open command prompt and we're going to type composer and this is the outputs the composer gives us and we have a lot of sub commands which we can use now let's see namespaces and autoloading in action okay on the right side i'm going to open autoloading folder it's index.php and right here in this folder i'm going to create two classes so one will be email class and second is going to be person class okay so i'm gonna require both of them in this index.php okay require once email and person okay in email.php i'm going to let me remove this i'm going to just create constructor which simply prints email class nothing else and i'm going to do the same thing in person constructor okay so echo person class br let's just save this and now on the right side actually we're going to create instances of this so email is new email and person equals new person so save and refresh and we see email class and person class now let's enable autoloading okay so how we can do that and also at the same time create namespace okay so i'm gonna generate composer json in that folder auto loading folder so for this i'm gonna create terminal and go to that folder and run composer init this will ask me couple of questions like what should be the package name and that should be vendor name slash the actual package name i'm going to leave this empty the description of the package i'm going to leave this empty the author i'm going to leave everything default hit enter a couple of times and then the file is generated now right here we can see that composer json which contains let's collapse the left side i did something wrong okay and right here we see that let's zoom in we see that the name of the package is this authors are this and this is the require inside require we write down all the dependencies the current package has okay now we are going to enable autoloading and we're gonna do in the following way we have to specify auto load right here auto load then we're gonna specify the standard using which we need that autoload and i'm going to specify psr dash 4 okay that is the standard and then we have to specify right here the namespace and i'm going to set it to up backslash that's going to be the namespace and the directory which corresponds to the namespace okay i'm going to set this to up directory okay now we have to create right here directory app and i'm going to move email and person both inside the directory and also open each of them and specify the namespace so right here we write namespace up and inside the email the same thing namespace up now the email in person does not exist without the namespace so inside index.php we're gonna have an error right here even if we fix that require once right here and right here we're gonna have an error because we are using email in person without the namespace and it doesn't exist we can see this immediately in the browser class email not found however if we just try to write here up backslash email and refresh we see that email class is found but the class person not found and if we do the same thing for person we will see both of them okay now let's do this autoloading and what is actually the autoloading and what advantages it has imagine that our application gets larger and we have hundreds of classes and the classes are just depended on each other we have to write this require once whenever we need that class right so auto loading gives us possibility to avoid writing these required ones for classes namespaces excuse me classes interfaces and traits i haven't actually explained what is interface what is trade that's i think an advanced part of object oriented programming and i really encourage you to check out more about this you will find a lot of tutorials and written articles about that but now let's enable autoloading so right here we specified auto load and we need to run composer update now so when we do this composer will create a vendor directory actually we just need to go to that folder 15 autoloading and run composer update let's wait couple of seconds it started reading that composer json and will create a vendor folder inside that 15 autoloading and inside the vendor folder it will create autoload php which will be the key file and responsible for autoloading all our classes and we won't need to write require once for any other classes and we will just include that autoload php which will be inside the vendor let's wait a couple of seconds until the composer update does this and then we're going to update our code and see it working so here is the composer update finished the work and right here we see that vendor and inside the vendor we see that autoload.php now i'm going to change that require once into just requiring vendor auto autoload php okay and that's basically it so if i just open in the browser and refresh we see the same output because all our classes email in person is automatically loaded by that auto loader the autoloader has a couple of other advantages in the composer general so the composer is a php dependency management tool and it gives us possibility to find some packages and install using composer so let's go to packages.org which is the main repository composer repository okay and i'm going to write here guzzle okay which is very popular package which gives us possibility to interact with remote resources that's basically an http client so i'm gonna install this using composer composer require causal http slash causal where guzzle http is the vendor name and guzzle is the package name so i'm going to copy this go to our project and right here run composer require castle http causal that will take a couple of seconds until it gets that package and grabs but it will also install other packages which are dependents of that casual http causal package okay so let's have a look in the documentation right here if we scroll down below we see how we need to use that so we just create a client with guzzle http namespace and then we make a request on the following url we make get request and then we can get the status code from the response we can get the headers and we can get the response body so i'm going to copy the following lines and go in the index.php okay i'm going to actually comment this code and paste down below the code copied from the packages but first let's have a look what the composer did so it started it actually installed six packages look at this and the last one is what we requested so first it analyze the dependency tree and install the other packages which are the like the required packages for the gazelle http cousin and finally that was installed so basically we don't care how many packages will be installed behind the main thing is that this package is installed and we can use that now we just paste the following code from packages save that and let's have a look in the browser refresh this and here we see so we see the status code we see the header and we see the whole response grabbed from that url and it is that easy to install other third-party packages and use them and that clients might be using many other classes if we scroll at the very top we see how many uh classes are included right here okay that use basically indicates that i want to use the following class in the current file that causal http is the namespace the cookie is the sub namespace and that is the actual class so we can follow using phpstorm control and mouse and we can see that is the class inside that namespace causal http causal cookie and it also requires many other classes from that name space sub name space and so on and all these things is managed composer and all the classes are included by composer so we can even change our email and person code and instead of having right here up emailing a person we can just write here use up backslash email and use up backslash person and we just use email in person just like this so basically using that use i'm telling the current file that i'm using up email and in the current file you should refer it as an email i can also specify an alias right here as for example just e and now i can use that class as an e class right here okay so this is how the autoloading and namespaces work now let's rewrite our crud application products crowd application using custom routing and we're going to implement a mini mini mvc framework as well so let's go to that folder of product squad and i'm going to create right here 0 3 underscore code so that's going to be the good version but again i want to highlight that if you want to implement the very best version of that product squad application probably you should think about using a popular framework like laravel or symphony or e2 or any others okay let's start with the entry script so basically we're gonna have one file which will handle the request and return the response and that's going to be the only file always so we're going to create right here index.php okay and that's going to be the entry script let's open now terminal and go to that folder and i'm going to actually put this index.php inside the public folder okay so we're going to have a web accessible folder and known web accessible files and folders in the index.php because it is an entry script it should be executed in the browser that should be inside the public folder so right now let's go to the public folder and i'm going to start php's built-in server php dash s local host and port 8080 i'm going to start it on port 8080 so the development server is started and now i can open the browser and right here type localhost port 8018 and we don't see anything right here because we don't print simply anything but let's just print right here hello world and refresh and we see hello world and no matter what i provide what path i provide like create for example or even create dot php uh in this case it actually searches for that file and it's if it doesn't find that file and that's why it returns that not found but if i just provide create or update so it simply prints the hello world because that index.php is the file which basically is always responsible for getting the request and returning the response okay now what i need to do here is that create a custom rotor and the configure that router for a couple of roads so what i want is that create router in the following way router is new router and i'm going to configure the router for example when a get request is made on slash let's use a specific class specific function okay so we're going to come up with an mvc structure which means that we need models views and controllers so i'm going to create right here controllers folder and inside that controllers folder i'm going to create a main controller and i'm going to also specify namespace right here that's going to be up controllers and we have to also create composer json and enable autoloading so let's open terminal let's open second terminal go to the folder that's going to be good and yeah right here in this good folder we're going to create composer json so composer init it will ask us couple of questions i'm going to hit enter on all of them and here we have that composer json now i'm going to open that composer json and configure auto load the autoload is an object with psr for standard we're gonna do the following for namespace up which corresponds to the current folder so any class basically which will be inside that good folder will have a namespace of up so let's save this and run composer update which will need couple of seconds but we can already create a rotor class right here so i'm going to create rotor with namespace up in that good folder so right here we have that namespace i'm going to collapse that and because we are using a get method on that router i'm going to create get method right here as well and in the main controller i'm going to create a main method which will be used right here in this index.php so we are actually doing products crowd application right so maybe let's just rename that main controller and call it a product controller okay so right here we will have product product controller as well and inside that product controller i'm going to create a public function index which will render the list of products and in the index.php i'm going to specify an array right here and i'm going to write write product product controller index what does this mean this means that whenever the url will be slash let's run product controllers index action okay what we need to do here is also that we need to require once from the current directory we need to require vendor not not right here so the vendor is one directory up we are doing this in the public index php so we need to go one directory back and from the vendor we need to include the autoload php so that all the autoloading is done by the composer so next we just need to you import that rotor so for this we can right here use up backslash rotor and we can do the same thing for that app controller's product controller so use up controllers product controller and i'm going to remove this namespace from here perfect after this when we configure all the roads and we're going to write a couple of more rows right here so when the get request is made for example on products slash create we're gonna execute a method product controller slash create okay right here so when the road will be products update we're going to execute an update okay so we need to do like this and we can also do an alias of that slash so we never get request is made on slash products let's execute the index and we also need to configure post requests so whenever post request is made on slash create we can execute other function or we can just leave and execute the same one so i'm going to leave the same function and we're going to differentiate in the function itself whether it is a post or get and whenever post request is made on update let's execute the same function and whenever post request is made on delete products products slash delete let's execute products controller delete okay did i miss something so we have an index gets get of create post of create get of uh update post of update and we have products delete so i think i haven't missed anything so now we need to actually implement that get in post so after basically we configure all the roads we need to also call on the router a method called resolve and that result will detect what's the current wrote and will execute the corresponding function let's open no router php and create these two functions actually three functions should be get and post so one is for get which will accept url right here in the function second for post which will accept url and function as well and third will be function resolve which will detect what's the current road so we need to save this given road somewhere so i'm going to create right here an array public array and that's going to be git rows which should be an array so i'm going to configure these get rows for the given url it's going to be the following function and down below i'm going to do the same thing for post let's declare it for post as well so post roads and down below this post roads for the current url it's gonna be the function perfect so we did that and now we need to detect what's the current road so for this let's dump once again super global server and we need to take that information from super global server so let's actually refresh this and right here we see that super global server and we're looking for the key where the update is there so the request yuri is this one and path info is the second one and we have php self also so we can take that path info or request theory but let's observe first what happens so if i add right here query parameter id equals 1 for example the inside the request you read that id equals 1 is displayed but not inside that path info and path info is exactly what we want so whenever there is an update we don't want that question mark id equal something we just need the url so in best case we should take the path info and make a decision based on that path info so let's do this so right here we're going to take the current url so current url will be from the super global server to take the path info and if path info is not presented there let's just take this slash because whenever we try to access a domain on a root domain without any path the path info is not presented there in the super global server and we can have a look as well right here save and refresh let's remove this and we don't see path info so now we have the current url and we want to take that function from get roads or post roads so we also need the current method so let's search for method and right here we have that request method so let's take the method equals from the current server we take the request method and right now we need to write an if statement so if method equals get we need to take that function from these get rolls for the current url so if the method is not get and it is post then we need to get the function from these post roads for the current url and right here we can dump that function what is this refresh and right here we see that the function which needs to be executed is up controllers product controllers index so if we just put right here create then we see an error problem on rotary php's line 37 so let's have a look 37 right here inside the get rolls we don't have anything anything configured for slash create that's obvious because we have configured slash products slash create so we might have other crowds in our application right it might be offer orders or invoices and that's why we need that product create so in this case if we just try to access a non-existing url not configured url we should show not found to the user right so here we can do the following so if for the current url there is no function so we can put right here double question mark if this is set return this one if it is not set return now and do the same for the post roads return now then we write an if statement if function exists let's execute that function if it doesn't exist let's just immediately write page not found okay so i'm going to move this var down at the very top save and refresh that and we see page not found which is good which is correct however if we specify right here products slash create we see that this is app controllers product controllers create and if we go into product controller right now and create that functions so duplicate these four times one for create second for update and third for delete and let's put enters right here in the from the index i'm going to echo index page from the create i'm going to echo create page and from the update and delete i'm going to do the same thing update page echo delete page save and yeah this is good let's go to the router right now and whenever function exists we need to execute that function so for this i'm going to use call user func so which is a special function and whenever you pass a function to that function it will execute this so in this case i want to execute this fn and i'm passing this to call user function save it and refresh and we see create page right here if i just remove this and leave this as it is i see page not found let's just remove that slash and i see index page if i specify update right here i see update page if i specify delete right here i see page not found probably because we need to make a post request on the delete so that's totally uh fine now what we need to do is that actually render a create form or index from that controller so how to do that let's actually set up a connection to the database so i'm going to create a database class right here inside the app namespace and inside that database class i'm going to create constructor and inside the constructor i'm going to create a pdo so i'm going to actually copy and paste couple of things from the old code so let's go to the database and copy the following code and paste right here the only thing i'm going to change is that i'm going to make this pdo as a class property so let's create public pdo pdo pdo so i'm telling that the pdo variable pdu property is an instance of the pdo so the type is a feature of 7.4 if you don't have php 7.4 you probably won't be able to not probably you won't be able to actually write here and you will have a syntax error so you can also leave like this i can also leave like this and it will work but i'm going to specify the pdu i really like the typed properties of php 7.4 but right here we're going to have an error when we just try to make an instance of the pdo class because we are right now in the app name space and the pdo basically is the namespace is the class name in the global namespace so if i just don't specify any namespace the engine automatically tries to find the class in the current namespace and this will give me an error so i just have to specify right here backslash which means that the pdo is an absolute name of that class so i can do like this and i need to put that backslashes right here and right here as well or i can just use pdo right here use pdo and that's it i'm telling that i'm using a pdo class and in the following file i just i should be able to use it without any namespace and prefixes that's fine now i'm going to create this pdo this pdf equals new pdo and i'm going to do the this pdo set attribute so that's perfect we have the database class ready and i'm going to create a couple of functions right here so let's create first one to get products get products and right here we need to make a select so i'm going to actually copy this as well from the public products index.php let's scroll up and i'm going to copy the following code and paste right here so whenever we have the pdo we're going to use pdo so on this video we call the prepare we need the search keyword and we should not get from the super global git let's accept it as an argument right here search so we get the search which but we can also specify that by default the search is an empty string so that we should be able to call that get products without that search argument we're going to see all these things and everything may will be will become clear step by step so we get the search if the search is given we do this thing we select with like otherwise we just select like this and we return all that products so now we need to call that get products method from the product controller from here but how to actually do this and we also need to render form okay so let's do things step by step and let's say that i only want to render the form so now let's go to that folder good folder and i'm going to create right here views so we are creating mvc framework mini embassy framework so we need views as well so inside views i'm going to create a file for actually let's create a folder for products first considering that we might have other card applications products inside the products i'm going to create a create php and let's create other views as well so we need index.php and we will need update php and we will need form as well which will be reused for create and update so let's create underscore form just like this one and we will also need to create a layout so we will need the header and footer to be written in a single place and use that but first let's implement the rendering of the form so i'm going to write in each of them an h1 tag create new product let's go to the update php and do the same things right here update product let's go to index and write product list now let's go to the rotor right here and i would like to create a method right here which will render the view so public function render view and this will accept the view name view and should render that view how the view should be rendered i assume that the name of the view will be just products so the relative path inside that views and in this case i should provide if i want to render the index for example i should provide products slash index so right here i'm gonna write include once from the current directory let's go inside views and let's use actually double quotations right here let's go inside the views and then use that view dot php so if the view will be products slash index right here it will be written products slash index.php which will be correct so let's just save this and we have that render view working and i now want to use that render view in the product controller so i need to somehow access the router right here so let's go back to the rotor and pay attention to that call user function so this is the router class and rotor executes that function call the fn and the fn will be this index or create or update so whenever we execute that fn we can also pass an argument and using call user function we can specify arguments separated by comma in this case i want to specify router so i'm going to specify this and i'm going to accept accept that router right here as a variable normal variable and on that router i can actually call render view and specify products slash index so i can also specify that the rotor variable is an instance of the rotor class but i have to import use that router right here so if you're using phpstorm you can hit alt and insert hit enter and it will import the class for us right here or you can write this use up router manually so so far so good and when we render the that view we can just return the value uh from here or we can just leave this as it is inside the render view we are including the file so this already means that it should render something so let's open now index.php not the php but the index page and right here we see that product list so this means that we successfully rendered that product index.php however pay attention one thing if we have a look in the page source we see that this is just h1 it doesn't have any header and footer of html and thus we don't have any stylings so we need these to be rendered inside layout so let's go ahead and create layout right here inside the views i'm going to create underscore layout and inside that's i'm going to put the header and the footer so i'm going to copy this from better views partials header so this is going to be the footer header excuse me right here and we can write body in html right here and this is the place where i want the content to be outputted so i'm going to output right here a variable called content so but the what is this content and where does this exist the thing that it doesn't exist yet uh at the moment so we have to create that content let's go to the uh router where we actually render a couple of things and do the following so first i would like to include a content of that view and save it in a content variable so if somehow i managed to save the content of the view file in a content variable then i can include the layout.php and if i have a content variable already declared the layout will simply use that content variable and just print it correctly right so how i can do this when i include something it automatically sends the output to the browser but we need this in a variable for this in php there exists output caching methods and we need to call upstart which means that i want to start caching of the output and basically every statement which sends an output like echo or include or anything it will be just saved in a buffer local buffer it won't be sent to the browser and in this case we include the file that will be saved in a buffer and now i'm going to call a method ob get clean which returns that output and cleans that buffer so i'm going to save this in a content variable now so this is basically what i wanted now i have a value html of that view file in a content and now i can include from the current directory i can include that layout.php and because the layout.php needs content i also have a content variable created right here and that should render it properly so let's save and have a look in the browser and here we see so we have header we have footer and inside we have product list that's perfect we can have a look right here as well so fine now let's actually do the following in the product controller let's use the database which we just created that function get products to get all the products and pass it down to the view so this is what we need to do but how can i access an instance of the database it is not even created yet so let's go to the router and i'm going to create an instance of the database right here so let's create constructor and let's create also public property database which i'm going to call and db and now this db equals new database and this is the database which stabilizes establishes the connection to the mysql so now in the product controller i can access the db in the following way router slash arrow db not slash arrow db and the db has a method get products and optionally i can specify search but i'm going to do without search right now so that should give me all products i want from the database and i also want to pass this to the view but first let's see what this product's variable is actually so save and refresh and right here we see eight products and each of them is an associative array and this is exactly what we want right so let's pass this to the view and i want this to be passed as an associative area so the products key corresponds to the products variable so the render view does not accept parameters yet so we have to go and configure that parameters let's delete that comment right here i'm going to specify params which by default is an empty array so if we don't want to pass anything so it will be an empty array by default and now i'm going to pass that and make it available inside the view so whenever i open that create php and i dump right here that products i should be able to see and i even want to iterate over these products and render them so how to do that so pay attention and from products controller i am passing an associative area where products key corresponds to products a variable now inside a rotor php i'm going to iterate over the params and i'm going to iterate as a key value here because it is an associative array and i'm going to do the following thing so i write key and this key is basically string value right so we pass products as a key and this will be key string products so i can put another dollar sign in front of that key dollar sign key pay attention to this which means that it will create a products variable so this is a product string i'm going to put dollar sign in front of that which will create a products variable and now this products variable equals to value which is what is passed from the controller so zoom out and here we have using this approach we created products variable and because we are including that create php or anything what we want in our case because we pass right here products variable for the products index actually we should do this in the index right here so we should be able to see the result of that for dump so let's go to the product controller no let's go to the rotor and yeah exactly everything works fine so now let's open the browser and refresh that and we see product list and the list what we what we want so now let's copy s couple of code from that um where it is public products index.php that's also the disadvantage of that that structure so you cannot really understand where the code is so let's actually take the table let's let's take with the search form and everything basically the create button itself so take this everything including the table go to the products index and paste right here so perfect so we have that products and we also need that search variable which we don't have but let's actually have a look without that so refresh and inside the search we have an error that undefined variable search but we actually see that products list exactly as we want so images are not there but we're going to fix that and css i think is not included also so let's copy from public up css into our public up css and we should see so here it is is for this search it is very easy let's open product controller and right here create a search variable which equals to take out the search from super global get if there is no search in the super global get let's take the empty string and we can pass that search also in the get products to filter products properly and we can pass that search to the as a param of the view and now the search variable will be created inside that index.php right right here actually i'm going to close that i don't want so here we have let's refresh in the browser and the error basically disappears and even the filtering should work if i just type test it filters and shows only products which contains test right there so let's also move images from that better folder let's go to public paste right here so we have that images let's refresh it and here we see the images now let's implement update uh create update and delete so when i click that create product i have the following error so we just need to change this let's go to the product index right here and i'm going to specify slash products slash create is the url we want to access so go back refresh click that create and we see that create page we have to of course create an actual form let's go to the product controller scroll down and we're gonna render that view so i'm gonna copy this paste right here and render products create and let's accept rotor as an argument right here we don't want any parameters to be passed isn't it so if we just open the better version if we just go to public products create and then we include right here form does the form need so it needs product for update and it also uses i think the title description and price okay so let's first take this whole form including errors and paste these in our create we use products create right here so we have a couple of variables we have errors we have product and we have title description and price so i'm going to change this in the following way so in the product controller right here i'm going to create a product variable which will be an associative array and this will contain itself title as an empty string description image and price so here we have image and here we have price and we're going to also describe right here errors as an empty array and we just need to pass that errors and products right here as a view parameters so now let's just pass a single product right here and errors so here we have that errors and product all right let's now open that create and have a look so we have an undefined variable title and description that's logical so let's go to the product and right here we are using the title and description but we're going to change this into product title and product description so we should also have product price save and refresh so this looks good and now whenever we fill the form and hit the submit it's the code will come right here so we just need to handle the uh code properly for submitting the data for this i'm going to write an if statement so if superglobal servers request method equals post we have to actually save it in the database so for this i'm going to create a product model so let's go to uh in our good folder and i'm going to create models folder right here and inside that models folder i'm going to create product class which will have a namespace up backslash models so let's say this that that product class basically will be a mapping of the class into a database table so this will have properties which will be columns in the database so public for example integer id which by default will be null and we need to also put a question mark right here which indicates that the id property can be optional it can be actually null so if i just don't specify that question mark we're gonna have an error that the id must be an integer but you can't assign now to it so when i put question mark it means that i can assign null to it so we have to specify uh public string which will be the title of the product okay we can set this to null as well and duplicate this couple of times we need public string property for description and we need that property for price but it should not be string it should be float we need also image path so image path that's going to be a string and basically every each of them can be null right we need question mark right here and i'm going to create one more property which will be an array and that's going to be the uploaded file so which we're going to pass so that's going to be image file so just like this one and that can also be be optional so now what we need to do that i'm going to create right here inside the product class a public function load which will accept the data and assuming that the data contains all the necessary information we're going to take out data um from that variable data and assign it to the properties of the class so for example this id equals data id but if the id doesn't exist inside the data let's assign now this title equals data title and we know that the title is required so i'm not going to write the double question mark null right here so we need this description equals data description and i'm going to write here also question mark question mark an empty string and this price equals data price okay and price is also required and what else so we have this image file also equals from the data to accept image file but that can also be um optional and if it is not provided let's just assume it is a null and then this image path image path equals data image and if that doesn't exist we can also assume that this is now perfect so we make the data loading and we need to load data from the product controller so right here in the product controller we get the data from the post so what we need to do is that a sign that products uh title product description the post data assigned back to into product title description and image and we also have to create an instance of the product so i'm gonna do the following so i'm going to rename this product variable into products that should be oops so that should be product data and then i'm going to write product data title equals from the super global post to take the title and repeat this for description as well and price and for image file as well so image file product data image file equals from the files super global to take out the image and if the image is not presented let's take out the null so now we just need to create an instance of the product which we just created uh of the product class which we just created so product okay just like this and i'm gonna call on the products instance load method and pass the product data so i basically load everything what i have right now inside that product model and now i should be able to call simply product save on the product model and we have to implement that save and if save is done then we have to redirect user to the index page so that should be slash oops that should be slash products just like this and we can exit right here as well so let's implement that save so for this let's go to the product and down below i'm going to create function save and let's declare an area of errors right here errors and let's do the validation so if this title doesn't exist so we know that we loaded the data into these properties okay this title this description and so on so if this title doesn't exist inside the errors we just add uh product title is required so next thing is if this price is not provided we just write inside the errors a product price is required and so we also need to uh actually we need to have a look at the old logic right here so that's going to be inside validate product so here we have the validation then we need also to create the public directory and then upload the image so let's just take this code and modify so here we have to create uh the directory but let's fix the path so we are in the products in the product model so we need to go one directory back from the product model and go inside the public and create there okay so the next is to if there is name there are no errors let's just copy the following code and paste right here and fix everything what needs to be fixed so the image basically is this image file so we don't want to create that image variable instead where we use the image variable we can change this into this image file so that's going to be this image file so when we don't want that image also the image path is this image path so right here right here we need to use this image path in this way so we delete this one and now we need to use so this basically is an if statement which checks if the product is in update phase and if the image basically is already there we need to just delete that image so for this we need to write if this image path exists okay let's just delete this image path this image path but we need to fix that directories as well call one directory pack right here go one directory back right here and right here so and we need this image path right here as well so let's have a look so we obviously don't have that random string and we need that function but except that i think everything looks good and what we can also do return errors from that save so let's just take the errors and return from here so that we can use that errors from the inside the controller so if we go in the controller and that product save now returns errors so errors and we just write an if statement so if errors is empty it means that everything worked perfectly and we can redirect user to the index otherwise the errors will be basically passed down to the render view and it will be rendered so let's see how this works inside create php we do display errors so this should actually work perfectly so let's refresh and just hit the submit and we have very first error right here typed property price must be float or null and string used that's obvious because right here from the product controller everything basically taken out from that is a string so we can cast this into float float in this way so save and refresh and here we have it so we have the product title is required product price is required but for some reason we don't have product title and product price right here so let's see why this happens so we take the product data and pass it down right here so let's just print what's the product data a refresh and this is the product data which doesn't contain anything obviously we haven't passed anything and that's the reason so let's just write something some cool title hit the enter and the title contains that and it is populated so if i just remove the title and put some price hit the enter the price is there but the title is not there so if i just put the title as well test five hit the enter okay something went wrong yeah basically everything went smoothly except one thing so the validation worked so we did saving but we haven't actually saved that in the database so we need to do this as well and let's implement this method in the database php let's go to the database and right here down below i'm going to create a function save product and we accept right here uh product actually we can create separate methods for save product and update product or we can do just once so let's call this create product and create separate methods for them so we have that create product and that accepts an instance of the product so i'm going to copy this script copy and paste from the public products create scroll at the top right here we have that so copy and paste right here and we need this pdo prepare insert into products everything looks good except that we need to provide right here product title product image path product description and product price so let's use the multiple cursor product oops product title and everything like this okay fine so that should actually already make a record in the database let's go to the product and after we actually save this in the database we need to call right here we need to get the database instance and we need to call create product on that but how to get the database instance so we can actually access the database instance through router right here but we don't have even router right here in the product so what to do in the database we can create a static property right here so we know that the database instance is a singleton object and that singleton object is an object which um a singleton object is an object which exists only one instance of that class so this is the singleton and we don't have two instances of the database class right so we need to access that singleton through the static property so i'm going to create public static database db right here and inside the constructor whenever we create this pdo after this i'm going to call self as a static identifier self db equals this so the instance basically is saved inside the static property db now in the product i can access database and db in this way and let's save it in a db variable and now i'm going to check if the current product this product has id this means that we have to update so i'm going to call on db update product which doesn't exist yet but we're going to create and i'm going to pass this right there however if it doesn't have id then i can call create product and pass this so that should already work and create product for us let's go to the product page test five the description the price hit the enter and we see this test five however we haven't uploaded image and it's it also doesn't display it properly we're going to get back to that image or let's check immediately right here so why it's there it's not there so okay so the image basically is empty string and it should not be even displayed right here what is displayed so slash is displayed right here okay so this image tag should not be displayed let's have a look in the index.php and scroll down okay and we need an if statement so php if product image exists let's display this image tag otherwise we don't do anything and we call and if save and refresh and we just don't see an image okay looks good and let's try one with image uploading choose an image test 6 test with some description hit the enter and here we have a problem that's about calling a random string so we don't have that random string function and what we can do is that we can create that functions.php right here in the good folder and just require once just like we are requiring autoload right here or we can create we can do with a more object-oriented fashion and i'm going to create right here helpers helpers folder and i'm going to create there um probably a string helper okay string helper uh that shouldn't be a folder maybe that should be class string helper that should be up backslash helpers this is going to be the namespace or let's just call it utilityhelper so util helper okay hit the enter that util helper is created i'm going to delete that string helper folder and inside that util helper i'm going to create that function so let's just take this and paste right here just i'm going to make this public static function random string so now in the product i can just call util helper column column a random string as a static function and that should work let's just save and reload and here we see the product with the image okay what we just assigned now let's see how we can do delete and update so let's do delete first it's it's easy let's go to the product controller scroll down and right here uh we need to accept first rotor okay on the rotor we need to access to db and on the database i would just want to call delete product so delete product and pass their id let's get the id using method post so id equals from the super global post let's take the id if the id is not presented there let's take the null and if that id doesn't exist let's redirect user header to the location column slash products okay exit right here and in the delete product i'm going to pass that id and we need to implement that delete product and whenever the delete product basically happens we also need to redirect user to the products so i'm going to put this right here as well and let's go to the database and implement that delete product right here public function delete product it accepts an id and we just need to deal it so i'm going to copy and paste this from public products delete php these three lines perfect paste this right here these pdo so everything should work that you delete the product and redirect user to the products list so let's have a look refresh and let's delete a couple of others and here we have the problem so we just need to fix that views products creates not the create but we want index so we just need to fix the path right here so it should be submitted on slash products slash delete right here and we should pass that id as a hidden input so that should work let's go back and refresh and just click on the test product okay it was successfully deleted okay perfect and we need to fix right now the update so slash products slash update so i'm writing here slash products which basically means that after the domain i want to this to be the road so let's remove the dot php so it should be slash products slash update after the domain so that's good so let's just save the file refresh and hit the edit and we see that update page now let's go to the product controller and accept a router right here router that should be a router variable and we get right here an id from super global get if that id doesn't exist we take now if the id exists more specifically if the id doesn't exist we redirect user to the products page let's do this however if the id exists we either need to render or we need to update okay so first of all we need to select so the product product data equals rotor db get product by id which doesn't exist yet so we have to create that so when we create uh we can already render the view router render render view pass their products slash update and pass write their product to be product product data so let's implement that get product pid in the database so i'm gonna do this at the top right here public function get product by id we accept the id and we just want to select it so i'm gonna do this in the update php not here but right here at the top where it is this is the code we are looking for uh that should be written right here so that should be this pdo prepare okay and finally we just need to return that product so this looks good now let's actually open that form update right here and we just need to include the form just like we are doing but we're doing this in the create php so that should move that form should move inside the form so right here i'm going to put that form and i'm going to include that form right here and i'm going to do the same thing in the update because we need the same form so let's go to the update and include that form right here and let's have a look refresh and this is our product page so let's go back so we need that go back button let's copy this from the create we don't even have on the create so let's just open that and paste right here and on update as well refresh go back to products and we need to change these to be products just like this refresh go back to products edit another one and we see all the information filled up go back to galaxy and i don't see description is that because we don't have no we have the description so now let's do the actual updating of the item and i think we are done so let's click the edit and whenever we change something the form will be submitted in the product controller and that should be the place so right here i'm going to write if the server request method will be post what we need to do is that just populate title description price and image file inside the product data so that should be product excuse me that should be title actually we can copy this from the create so these four lines so we just copy this paste right here then we create an instance of the product basically we need the same thing right here as well okay paste right here and if that returns error if that doesn't return error we redirect to the index otherwise we just display errors and we need errors to be used right here as well so here we have that errors and let's describe the errors at the top as well so if for some reason i open the edit form i remove the title and hit the enter i should see that product title is required okay galaxy note 20 i'm gonna hit the enter and let's see what happens update product doesn't exist obviously yes because in the product we have written right here update product which is not actually implemented let's go to the database php and i'm going to create update product which will accept an instance of the product as product and let's open um update right here scroll down and copy the following code and paste this right here so this pdo and we prepare and we we do everything as we we're doing just right here we need to specify this uh the product title product image path description everything like this so i'm going to copy and paste this right here and it should be product id okay let's just save this and refresh and let's just try so updated hit the enter and here we see that's updated so this actually works so we have implemented everything basically and now let's have a look at the source code how it looks and compared to the old one so right here we have that structure controllers helpers models public vendor which is uh right now we don't have any third-party packages but if we need the third-party packages this will go inside the inside the vendor and inside the controller this is a product controller which contains all the logic regarding the product so we can see them as separate methods and we can even collapse couple of other methods and focus on the other one which we are interested for example on delete and collapse everything and the code will be much more readable and visible in the views we have separated inside the creating update all of them basically are very clean very minimalistic the most logic is inside the form and inside the index.php but that's just a table in the form nothing else but the big advantage is that so we splitted that logic across multiple files and we have like the single responsibility principle which means that the database class right here is responsible to set up a connection to the database and update product or delete the product or create the product and the product php itself a model is responsible to make the validation properly and return the validation errors and save the uploaded images and controller is responsible to connect the data like for example right here the products uh data inside the view so we have a full embassy so it's again it's like the minimalistic mvc we don't have all the great features the current frameworks have but we have models views and controllers all of them and our crowd application in my opinion is much more like advanced and much more like perfect than it was in better or in bed examples again this is not probably the best version but it's much better than we had before and it's not best version because again i will highlight that if you want best version probably you should think about using today's modern popular frameworks like laravel symphony e2 and others now let's create apache virtual host and make our application working on the following domain products dot test so whenever we type this in url we should see our products crowd application for this we need to go to the exam installation directory go to apache conf extra and we're going to open httpd vhosts.com file so i'm going to open this and this is the file which contains all the virtual hosts on on our example installation and down below if we scroll down below we should see virtual host text so it looks like unlike the xml or html text so and right here we just need to create new virtual host i'm going to copy and paste this and we don't need all the properties right here i'm just going to leave document root i don't want server admin we need document root we need server name and i don't even need error login custom log so i'm gonna remove the comments right here and the only thing we need is that htdocs directory to be configured properly okay so in this case we need to specify right here the folder inside which the index.php file is and which should be the entry script so if we just open our xampp directory go to htdocs php crash course let's go to product squad go to the good solution in public so this is the directory basically which should be served for that virtual host so i'm going to paste this directory right here and for the virtual host i'm going to name it product squad products dot test okay that should be the virtual host name and right here we also need to specify the directory tag so i'm going to copy and paste the following directory tag and explain everything okay so this is the directory tag so we specified the same same path right here inside the directory and for that directory we enable a rewrite engine which means that everything what is not a file or it is not a directory redirect to index.php so index.php will handle all the requests if the request is not made for the file and for the directory so now let's go to windows folder on the c drive windows let's find system 32 folder right here we need drivers etc and we need to open hosts file and we need to make a one change right here to make this virtual host working so we need to write that whenever we ask for products dot test domain we should serve from a local ip address which is a hundred and twenty seven zero zero okay that should be the ip let's just save this so we cannot save until we retry this as admin i'm going to click that button it will make a neat couple of seconds yes and the file was actually saved but because we changed the virtual host file we need to restart apache so let's go to the xampp installation go to actually scroll down and open exam control stop this we need to accept that and start it [Music] so after this let's just check if that domain works fine so we refresh and here is our products credit application up and running on that domain however we made some bug while we were developing and i didn't tell you about this and now it's time to fix that back so now if i just click on create product i still stay on the product list page the url basically changes but i'm still on the product list page and why does this happen let's have a look in the source code so the bug basically is inside rotor php so right here when we take the current url from the path info that path info only exists when we start php's built-in server so if we start the application working using apache's virtual host in this case this actually doesn't work and that's why we have that problem so to fix this we need to change how we actually get the current url so again let's dump right here what's the current super global server and exit right here and have a look refresh and this is so let's search for products slash create products slash create and down below we have that a redirect url and we don't actually have that path info as i mentioned so we need to take that from the redec redirect url however there is one thing to notice so if we just specify right here query parameters for example id corresponds to something in this case a redirect url contains where is that not the redirect url it's my bed so we want to um let's search for products how it is called products request yuri so this is what we're looking for so request yuri and if we just specify right here id equals to some number in this case this request yuri contains that id as well so it's right here request yuri so we just need to extract the products slash create and just take that before the question mark to make this working okay so let's go to the source code and take request yuri and if it doesn't exist we take this slash however we need right here to take that to take the substring from zero position until the question mark okay so we just write if uh str pose inside that current url of the question mark is not false which means that if question mark if the current url contains the question mark in this case the current url should become substring of the current url from zero position to the position of the question mark okay which is the str pose current url of question mark okay so let's have a look at that current url and exit right here and we don't want exit oops right at the top so let's just save and refresh and that's the products create so even though we have the question mark right here we took it correctly so let's just remove this refresh and we have slash right now so if i just remove this exit and we updated the current url save that and refresh we see list if i click create product i am redirected to the create new product page and this will work fine so we just set up the apache virtual hosts okay let's talk about now sessions and cookies sessions and cookies both are technique to save some data for that specific user who is accessing the browser but there is one big difference between sessions and cookies so if you want to save data inside session the data is saved on the server side however if you want to save data in cookies that data is saved on the client side and it the data basically is passed to every request and response and using that cookies data server and client can communicate to each other let's start a session in php so i'm going to use a function session start session underscore start and now let's open sessions and cookies page counter okay and i'm going to inspect the page and let's have a look in the application cookies area okay let me enlarge this so right here we see php sesh id whenever we start session from the php this basically creates that session id so because we called that session start it created that session id and saved inside cookie basically server told the browser okay so let's start communication with each other and i'm going to give you that unique identifier php session id this random string and whenever next time you want to make requests to me so basically send the following session id so that i know who you are so if we have a look in the network and if i just refresh the page right here the client makes requests on that page counter right so if i go in the headers uh no in the cookies area right here we see that the following cookies are passed and based on that session id server can understand that hey this is the same user who made a request like several seconds ago so i just need to do something which is relevant to that user so sessions very often are used to save like the user information the user id or username or things like that so let's actually implement a page counter okay so i want to track how many visits the user made on that page and then if the user for example visited 10 times or 100 times i'm gonna like show some present for that user so this is just a sample sample mini mini project okay how to do this first of all i'm going to show you also that that session id can be used in the code as well okay so i'm going to print right here [Music] session underscore id okay and this is this same idea which is written in the cookie so i'm going to refresh the page and right here we we see that q0b something if you go in the application we see the exact same one so if i just delete that value from cookie and refresh the page this server basically will see that there is no session id in cookie so it will create new one okay and right here we see the new one and right here as well okay let's see how we can set some things in a cookie so for this we need to use super global variable underscore session and that session is associative array and i can pass some values right here i can write name equals zura and then i can dump the whole session not server but session save that and refresh and right here we see name equals zura right now even if i remove that name equals zura save it and refresh i still see that name equals zura so that's because once it is saved in the session it is not deleted until we delete that session id and lost the connection between the client and the and the server or we just manually remove that value okay perfect so if i want to manually remove that value from the session i'm going to run unset i'm going to pass session name so let's remove whatever is written inside session name so i just save that and refresh the page and on second refresh it basically disappears or i can run a method session unset session unset which basically removes all the values from session so let's create that page counter i told you so i'm going to write here so let's remove the session id i'm going to write here inside the session for page counter i'm going to do the following so if inside this session page counter already exists and for the first execution we know for sure that it won't exist okay so if it won't exist let's take zero but if the page counter exists inside the session let's leave whatever is there and after this i'm gonna increase the page counter by one page counter plus plus so on the first visit this doesn't exist so zero will be assigned to page counter and it will be increased and will become one on the next visit page counter will exist inside this session and it will be just increased so i should also tell you that you should run session start as a very first thing in your application so you shouldn't output your html or do anything else except like running session start so when i do this then we need to check if session page counter reaches 10 we do the following so we can output something thanks for visiting us 10 times and we can also unset everything from session and we can even destroy the session session destroy okay so session onset basically removes all the values from the session but it doesn't destroy the session so you can still set some values after session and set so i can run here session test corresponds to something so session and set just removes but i can still write values there for uh if i just run session destroy it is impossible after session destroy to set some values inside the session okay so i save this and i refresh the page and let's also print how many times i visited so down below i'm going to write my awesome page comma visited php equal session page counter [Music] times save and refresh and look at this so visit it two times i'm going to keep refreshing and this that one increases so if i just delete that session id this means that now server doesn't know who the client is so the client is new for uh for it for server and in in this case the page counter will be just not set and it will take zero okay so refresh and now i visited the very first time second three four five six seven eight nine and ten and right here so we see the following so thanks for visiting 10 times but because we unset the session we actually don't see that page counter anymore so what we can do is that just remove this page counter and have a variable right here page counter equals 0 for example and before we call onset we take that page counter from the session and save it in a variable and use that variable down below so that is necessary because whenever we call onset the values from the session is destroyed and we cannot use session counter anymore so we just save that and refresh and here we see visited zero times and let's see what's going on uh okay that should not be declared right here so we should do probably something like this so page counter equals if from the session page counter exists let's take otherwise let's take zero so save and refresh and here we see three four five six seven eight nine ten and we see that thanks for visiting us ten times perfect if i just refresh it starts from one again so very often sessions are used with cookies and this is the example so let's move on and talk about cookies so i'm going to open on the left side second file cookies php and on the right side as well so cookies are absolutely useful in today's programming in today's web development and cookies are used mainly for three reasons personalization session management and tracking so what do i mean by personalization so you have probably met that when you access amazon.com and you just start browsing the latest dell laptops for example and even though that you are not authorized you are just a guest user open it in like a different browser and you just start browsing just having a look at the dell laptops later when you open the amazon it suggests you a couple of dell laptops so that basically happens through cookies so whatever item you visit amazon sales that information inside the cookie and the cookie is saved in your browser and next time when you access the same website it takes the values from the cookies tells this sends it to the server and server understands what products you have seen before and based on that information it suggests you new items okay another example of using a cookie is google analytics so which tracks how many pages you visited which pages you visit it has also a possibility to keep track which buttons you clicked and so on and these kind of things are done using cookies and the third one is session management in the this is the perfect example which uh i showed to you about sessions um so sessions are basically very often used with cookies and yeah php sesh id is saved in the cookies okay let's see how we can create values in cookies or delete or update that values so for this we have a function set cookie and that's it cookie accepts couple of arguments right here first argument is the name so we can pass any string right here some key and the second argument is the value we can pass some value right here the third argument is basically the expiration date so when that cookie value should expire and i'm going to specify right here now and current time plus for example 60 seconds so this cookie value should expire in 60 seconds from now so there are a couple of other arguments but i'm not going to explain them so when i save this and refresh and let's inspect the page and go in application cookies right here we see that key corresponds to value so that php id basically is left because we previously accessed the sessions page so if i just delete both of them refresh the page it will create that key value okay which will have the expiration date the following date okay what if i want to update the value so for this i'm going to use the same function set cookie i'm going to specify the same key by different value value updated for example and if you want we can specify also different expiration date for example after one hour excuse me okay just like this save and refresh and right here we see value updated and if we have a look in the requests in the network refresh and click on this if we go in the cookies we see right here that these are request cookies which are sent to the server and these are response cookies which are sent from the server so this is how this actually works so the cookies are exchanged between client and the server so the server can write cookies client can write cookies you can write cookies using javascript as well okay and let's see how we can actually remove the cookie for this we just need to specify we we need to pass the same key the value basically does not matter but we need to specify uh past time so current time minus one for example which is the past time so if i just save this and refresh it go to the application we don't see that cookie value anymore and if i go in the network right here we passed the cookie from in the request this was the cookie and in the response it deleted that cookie the latest record so if i just refresh these and click on this so basically request cookies does not exist i didn't pass any cookie because there was nothing written there but the server just had returned with a deleted cookie so these basically occur all of them so sarah just set the cookie value and then updated that value and then deleted that value so if i just do like this so set cookie refresh the page refresh once again and the request cookie contains this one so now i'm gonna delete that set cookie and only delete the cookie so save and refresh and right here we see that we passed that value but server basically deleted that that cookie and we don't see that in the application as well so if i just uncomment this comment of this save and refresh so no cookies let's go to the network no cookies were passed or received that's that's all basically about cookies and sessions that's all guys and thanks for watching i hope you enjoyed and if so hit the like button and share this video if you want more php tutorials and challenges check out my channel thanks for watching and see you in the next time
Info
Channel: Traversy Media
Views: 313,298
Rating: 4.9585629 out of 5
Keywords: php, php7, php8, php8.0, php course, php crash course, php full course, php tutorial for absolute beginners, php course traversy, php crash course traversy, php in 6 hours, php & mysql course, php tutorial for beginners, php for beginners, TraversyMedia, php tutorial, php course for beginners, php crash course for beginners, TheCodeholic, php for absolute beginners, php MVC, php custom routing, php Products CRUD, php mvc framework, php mvc tutorial, php course TraversyMedia
Id: 2eebptXfEvw
Channel Id: undefined
Length: 387min 21sec (23241 seconds)
Published: Fri Dec 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.