PHP Tutorial 2021

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well hello internet and welcome to my ultimate PHP tutorial in this one tutorial you're gonna learn pretty much everything you could ever want to learn about PHP I'm gonna also cover MySQL and interacting with MySQL and PHP and a whole lot more underneath the video you're gonna find a table of contents you can click and jump directly to whatever you're specifically you would like to learn and this is basically gonna be about a six seven hundred page book all crammed into one video and I have a lot to do so let's get into it alright so like always all the code is in the description and also everything's gonna work exactly the same on Windows and Mac and I have an installation video if you want to have you the exact setup that I have for both Windows and Mac in the description and I'm gonna be using the atom text editor you can use any text editor that you would like but if you want atom just go to adam.com load the installation is very simple so I have some basic HTML here which I'm guessing you understand this is basically just defining we're using English and our character set and the title that's going to show up and then we're gonna start writing some PHP code alright so if you want to embed some PHP code inside of your HTML file it's actually going to be called Tut one dot PHP it's actually labeled as a PHP program you're just going to use this opening brace and this closing brace any PHP code that you want to run that before the HTML just place it before your HTML code and basically variables are going to start with a dollar sign like this and then after that you're going to have a letter so we could have something like first name and then after that first letter you can have letters numbers as well as underscores to define the name for your variables now the datatype that is going to be assigned to your variables is going to be based off of whatever type of information you put inside of it so if I put in a string of characters this is automatically going to be considered a string if I would however go back and change it thereafter into a integer well it's going to then be referred to as an integer datatype and basically you're going to have your string types like here I'll create another string type you're also going to have integers so I can define an integer which is just a number without a decimal place you're also going to be able to define floats which are numbers with decimal places we can have boolean x' which are going to be either true or false we're also going to be able to define arrays so these are just going to be a series of values that are going to have keys and values assigned to them so we'll have a key here which we'll call Street and then you can go in place additional information inside of there and it doesn't matter what your data type is so I can come in here and define a key for city and then assign yet another string to that and we'll get way more into a race as we continue if you would come in and define a value of null that's just going to signify that the variable has no value and we're also going to be able to come in and define constants that once set the value cannot change and I move pretty quickly in these tutorials so get prepared to hit the pause button just so you know this guy right here is just going to tell the browser to render using the html5 spec this is saying that we are going to be using English this is going to define that we're using the utf-8 character set here's the title for PHP and so forth and so on now we'll jump down into the body and start placing some additional PHP code in here and to display in line inside of the HTML what we're going to do let's say we wanted to go and create a paragraph and throw name inside of there we would then be able to go and get the name that we define just by going PHP echo and if I want to put the first name that the value assigned to first-name which I defined up here directly inside of here I would just list that variable name I can throw a space in there I can combine the different strings using just dots or periods I could then also go L and name and then you're gonna close off your PHP code with that tag and then we'll close off the paragraph with that tag and if we go over here and reload it you can see that it automatically is gonna print out my name and I enlarged it so you can see it a little bit easier you're also going to be able to pass data to a PHP script using forms and I'm gonna cover passing data using the get operation as well as the post get as you're going to see is going to pass values through the URL inside of an array and mainly you should use get in any situation in which you want to allow the user to bookmark the page and use post anytime that you would resend any data to the server if the user ever tries to send data to the server multiple times they will be warned in that situation but we're gonna use both just so you'll be able to see what both of them look like so I'm just going to come in here and create a form and action is going to say basically that I want to call this PHP script that I am currently using so I'll just say top one dot PHP which is the name of the file that we are currently inside of and in this situation I'm gonna use the get method would you define just by saying method get' then inside of here I can go well make sure that I close my form tag and then inside of here I can create some labels so that will show up and I'm gonna show you some insecure as well as secure ways of passing form data back and forth just so you can see everything go and allow the user to input a state in this situation and I'll give it the name of state so I can refer to it close that off throw in a new line there with break and then I'm gonna go and do this a couple more times so I'm just gonna copy this I'm gonna allow the user to come in and enter numbers and perform different mathematical calculations on those numbers and I'll call this number one and then I'm going to go and creating number two as well call this number two and call this number two after that we can throw in a submit button type equal to and submit give this a value of submit and close off that tag now underneath of our form that we just created like I said I'm going to show you some insecure ways of passing information and then some more secure ways of passing information if you would like to come in here and check that information was passed to our web page let's go and throw this on a separate line and let's close off this PHP tag as well you could say if is set and get and array key exists and specifically look for state get and then we're gonna throw a curly bracket inside of there and if this comes back is true what I'm gonna do is assign the value that was passed for state from our form above to our variable that we have here by referring to the array that's gonna contain all the values passed which is also gonna have num1 and num2 i can come in here and verify state's existence and also verify that the value assigned to state is not empty by going not empty that's what that exclamation mark means in their state and then i can come in and go echo and say something like you live in space dot and i'm going to show you numerous different ways to output information as well and then i'll say that i want the state to print out there I'm just sort of sticking with echo right now just because it's used a lot and let's go and throw echo here you're also going to be able with echo to go and use double quotes and in that situation you'll be able to embed the variable values directly inside of your output and that's specifically when you use double quotes with that go so here I'll say F name lives in and also do the same thing with state and also we can throw a break statements inside of there so everything is contained all in one area need to use all these dots another thing I want to do is I want to check how many values are inside of my array that was passed so I'll figure out how many pieces of data that were passed from the user to do that I can say if count get is greater than or equal to 3 say I have 3 pieces of information being passed here and we're going to go and perform some different math calculations so I'm going to say num1 and go and get the value that was passed from that and I'm gonna say num 1 and we'll do the same thing for num2 just change this to Nome 2 and change this to num2 and now let's go and output some information so I'm gonna say Nome 1 plus num2 is equal to then outside of there I'm going to make that calculation so I'll say nam 1 plus inside of the parentheses that you see there num2 and then after that throw a break statement inside of it and we can go and perform multiple different calculations let's just go and I'll show you what all those look like there's five of them so let's go negative and would also go and get that and we'll get a multiplication with a star and another one and we'll do division and division and modulus which is going to give you the remainder of a division and I guess I should also do another one you can also do integer division which is basically just going to throw away the remainder so I'll throw that right there and then inside of here I will say int division and then get rid of this parentheses and put it here instead and if we reload the screen I can throw PA inside of there and then I'm going to throw 5 and 4 submit and I made a little error I forgot to put in the dollar signs in front of this very important just sorta dollar signs in front of all of your variables at all times and I went and threw in some values inside of here and click on submit and you can see you live in PA Derek lives in PA got another warning down here instead of plus inside of there throwing a comma and now you can see that it works and we're performing all those different calculations just like you would expect you're also going to be able to perform calculations using numerous different shortcuts someone throw echo inside of there and I'm going to say that I want to increment num1 get rid of this and you can increment the value of number one just by coming in and throwing in two plus signs that's gonna make it go up and you're gonna see something interesting here whenever this outputs on the screen and we can also decrement num1 by putting two minus signs inside of there and I'm gonna show you a couple other different shortcuts the following if you would say I plus or equal to one is going to work exactly the same if you would go i plus equal to i plus one so there's another one and you can do this with division or subtraction or any of those other different options as well as modulus and why don't I cover a whole bunch of other math functions that are available and if I reload the screen you're going to see live in PA Derek lives in PA all of those other different things we covered you're gonna see here the increment is not showing this as six the reason why is what it does whenever you put this plus sign on the right side is it actually outputs the current value assigned to number one and then increments it and that's why you see that this shows up is six because the same thing happens whenever we have a decrement right here so it prints the value then it increments it prints the value then it decrements okay so that's just make that clear and then here are a whole bunch of built in math functions that we have and you can see exactly how to set those up and I'll scroll this up you can see we can get the absolute value we can see that there's numerous ways to round ceilings gonna round up floors gonna round always down and round is going to round either up or down depending upon if this first decimal place here is a five or some other value you can see we can get the max the min take four to the power of two we can get square roots get the exponent of E we can put logarithmic calculations and there's the different logarithm calculations we can perform you can see that pi is actually built in as a constant we can go and find a hypotenuse we can convert from degrees to radians and radians to degrees there's multiple different random number generators this one right here is a really fast random number generator it's gonna generate values from 1 to 50 and you can see down here came back as 1 if I reload that you can see now it comes back is 41 here's the original r and random number generator if you're used to PHP in the past this is probably what you've seen you can see here this is gonna return the maximum random number that can be generated you can see if a value is infinite or finite you can also check if a value is numeric you can also see here that I have double quotes inside of there anytime you want to use double quotes inside of double quotes just put a backslash and double quotes again and there are numerous different trig functions that are also available that you can also see right there on your screen like I said all the code is available in the description or you could pause your video and type all of this out and now I'm gonna show you a way to format your information in regards to decimals and working with them and outputting them on the screen so let's say you wanted to define how many decimal places actually show I'm gonna go echo number there's actually multiple different ways to do this as well as you're gonna see here in a minute so let's say you go 1 2 3 4 5 & 6 7 8 9 and you only want two decimal places to show up just throw a 2 inside of there period which is going to combine these two pieces of output I'm gonna throw in a break statement save that reload it and you can see that it rounded it to just two decimal places alright so cool stuff and now what I want to do is talk about using conditionals now the commands of if else if and else are going to be used to execute different blocks of code depending upon mall different conditions as you'll see and you're going to be able to use conditional operators to compare different conditions different values as well as use logical operators as you'll see you can also see here that I'm using a hash symbol to comment out my code to place comments and you can also use two forward slashes if you would prefer so what I'm going to do here is I'm going to define number of oranges and basically what I'm going to do in this example is calculate different discounts based off of the amount of oranges and bananas that were purchased by a customer so let's say the customer purchased four oranges as well as thirty-six bananas what I'm going to say is if the number of oranges is greater than twenty-five and the number of bananas is greater than thirty well in that situation I am going to give them a 25% discount and throw in a break statement there then what I can do is list a secondary condition so if this one comes back is false well I'm not gonna print this out obviously and I'm also going to give another opportunity for some other discount to be available however if this comes back is true we never even go down here so let's come in and create another condition I'm gonna say else if number of oranges is greater than thirty or so I can have either or of these come back as true and then I will give another discount number of bananas is greater than 35 well in that situation and you can see here the curly brackets the only code that's gonna be executed if this comes back as true or this comes back as true is the code inside the curly brackets well here I'm just gonna copy this in this situation I will provide a 15% discount and then we can continue onwards else if and here I'll say not and what not is gonna do is turn a true into a false or a false into true so I'll say not and then I'll have conditions inside of here so I'll say oranges less than five or and then again number of bananas less than five so if they order at least five oranges or five bananas well in that situation I will give them a discount but it's gonna be only five percent then if none of those things come back is true this is the only way this will execute and if it does I will say no discount and if we reload our page you can see they get a 15% discount all right so cool stuff and now I'll show you another way of working with conditionals and that will be with the switch statement so the switch statement is going to provide output for a limited number of options but you can actually tweak it and get it to do even better stuff as you'll see so let's say that a customer requests a coke what I can do is say based off of that request case so in case the value of request is equal to coke well in that situation I am going to echo out on to the screen here is your coke then what we're gonna do is type in break which is going to break us out of checking anything else now another option we can have here I have no idea why anyone would ever request a Pepsi over a coke but if somebody did I can say here is your Pepsi and then after that I can say default if they don't request either one of those things I can come in and say here is your water and break out of that and if we reload it you can see that they asked for a coke however you will be able to use really cool things inside of switch such as conditions so let's say I am instead going to tell students what grade they should go to based off of an age value so I'm gonna say age is equal to 12 and then I'm going to inside of our switch statement change this to true so what this is going to do is basically if a condition down here comes back with a value of true it is going to perform those calculations so it's sort of doing things in the opposite direction so I'll be able to do something like case age is less than five well in that situation I can stay stay home and then case age is equal to five in that situation I can say go to kindergarten and let's go and have even more conditions I could also come in and create a range of values so I'm gonna say case in array and array is going to take an array or in this situation a range and it's gonna see if a value is inside of it so I'm gonna say if the value for age is inside of a range of values from 6 to 17 well in that situation I'm going to calculate the grade that they should go into so I'll say grade is equal to age minus 5 and then output on our screen go to grade and whatever the value of grade is of course followed with a break statement and then another break statement and then after that I can say default if none of those things apply go to college all right so good stuff and you can see if I reload it that I get go to grade 7 shows up and that's because I assign the value of 12 to the variable age the ternary operator is going to be able to assign either one or another value based off of a condition so let's say I wanted to find out if somebody could vote what I would do is say that I want to check the age I guess I should have left this inside of here age is equal to 12 so if age is greater than or equal to 18 then I'm going to put a question mark if that comes back as true I'm going to assign the value of can vote to the can vote otherwise if it comes back as false I'm gonna mark this as can't vote so it's just a either-or way of assigning one value or another and then I could just say vote and then put can vote inside of there and you can see can't votes on this up all right so cool stuff another thing to be aware of is there something called the identical operator and that is going to be three equal signs in a row the way that's going to work is it's only going to return true if the value as well as the data type are exactly the same so for example if I said if 10 which is a string is equal to 10 now normally with just two equal signs that's going to come back as true but if I say echo they are equal and I'll show you both things here in a second else they aren't equal reload they aren't equal but if I change that to just two equal signs they come back as being equal just something to be aware of if you want to verify that data types as well as values are equal and now I want to show you some cool things we can do with print F now printf is gonna provide another way to format our output by basically defining what datatypes are expected to be printed out so I'll just say print F with parentheses this guy right here is called a type specifier and what I'm saying here is I expect a character to be printed D is going to represent an integer I'm going to be able to say that I want to use floating-point types and I only want to show two decimal places and also we can use strings now what I'm gonna be able to do is outside of here I go comma and this is going to be the character code 465 which you're gonna see here in a second I can also go and print out an integer one point two three four it's gonna cut off the four though when it outputs it and then I can just say string reload it and you can see the character code 465 is representative of the a and it prints the integer it prints the float like we like it and prints the string and you're gonna see a lot more with print F store now when we talk about strings alright so you know that strings are just gonna store a series of characters so let's go and create a random string and I'm going to throw some extra whitespace here just to show you how to get rid of that extra whitespace so if you would like to get the number of characters in a string you could do something like this and we could say length and it's going to be an integer then we would say string length and throw inside of here are random string let's go and do a whole bunch more of these let's say that we would want to trim the white space to the left the command and say trim L and then actually let's leave this as length so you can see the length changed and we'll leave this a string length but inside of here I'll say L trim which is gonna trim the white space on the left of our strength likewise we will be able to trim the space on the right so let's change this to our trim we could also come in and trim all the white space so we'll say random string is equal to trim and then throw in our random string again we're also going to be able to output all of our string information in all uppercase letters just change this the string get rid of this get rid of these extra parentheses which if you have too many parentheses you will get an error and then STR to upper and you're gonna find out what these functions are here in a minute whenever I cover functions in detail and lower and then just change this to lower so string to upper string to lower we would also be able to come in and just have the first character set for uppercase to do that you say you see first we're going to be able to come in and let's say that we would want to get character starting at the very first one to the end let's go and change this to first 6 so the first six characters inside of our string well that would be a sub string smaller than the main string and what we would do is just put random string if you want to get the first character you would put a zero and if you wanted to get up to the sixth you would put a six inside of there that's a lot of information let's run this you can see how the different sizes of the strings were affected by trimming the whitespace you can see there is in uppercase there is in lowercase that is with the first character set to uppercase and you can see how we grab the first six characters out of our string of course there's way more functions let's say that we would want to get the location of a string and these are referred to as indexes so this will be the first index or the first character this would be this sixth index or the sixth character more and that is whenever we get into arrays which is coming immediately after I cover strings so what I want is the index or the character number that represents where we are trying to search for a string and this guy is string position and again you just pass in random string you want to search for and then in this situation the string that we are looking for which is the word string we would also be able to come in and replace one string with another string so you say random string is equal to string replace and I'm going to say that I want to replace string with the string characters and then put in random string which is the string that we're working with and it will do that for us and we could go replace and then this is just going to be random string I just want to show the fact that it went and actually changed that part of our strength for us and then we're also going to be able to compare strings so let's go printf and we'll say a equal to B and then we'll throw a D inside of here which is going to give us our boolean value in this situation and this is string compare and what we're specifically checking is the string that has a inside of it and the string that has B inside of it reload it you can see here index or index seven is where we are going to find the beginning of string you can see here that we went and chained random string into random characters and you can see here whenever we tried to compare these two strings we got a value of negative one you would get a value of zero in the situation which they're equal you would get a positive value if the first string was greater than the second string or a negative value in this situation in which the first string is less than the second string all right so we'll be doing way more with strings as the tutorial continues but now I want to talk about a raise alright so on to a raise now a raise as I have mentioned previously store multiple values so let's say I create an array called Friends I'm gonna then gonna follow that up with the word array and then I can I don't have to use key value pairs I can just go and throw anything inside here that I would want and these would then be given index values now you're going to be able to access them just by going and listing whatever the array name is and then the very first index is going to be 0 and we can throw a break statement inside of there now let's go and do a couple other things you're going to be able to add values so I could say that I have a friend named Steve which I did once and there we are I can also cycle through the Rays I'm gonna get more into looping here in a second but basically what this does is it says for each friend as I cycle through the array I want to temporarily store each friend in a variable called F and then what I can do is just come in and say print F and I'll be able to get each of the individual friends out of it and print them on the screen just by referring to F inside of that printf statement let's go and do a couple more now as I said I can go and assign key value pairs which are sometimes very useful just by listing the key and then a little arrow looking thing and whatever I want to put inside of it would be kind of funny if I actually did live on a 23 main and there we go and then I would also be able to use for each to output the keys and the values so once again the array that I'm working with and then the key and the value and then we can come in and print all that information and I'm just gonna come in here and throw a string and a string inside of there and then change this decay and then change the or add on a V it gets enough information let's reload it and you can see how we are outputting all of that information now you're also going to be able to combine arrays so I'm gonna say friends my current array there already exists well you know what I'm gonna call this friends too and I am going to list dog as a friend then I can go and add dog to my already established friends right just by saying friends the original array and friends to the array is created there now they're all going or dogs basically gonna be put inside of friends you're going to be able to sort the array in this situation it would be in ascending order I would also be able to reverse sort these array items by just going reverse sort so that would be in descending order I would also be able to sort by key values and to do that you just go a sort and that a stands for associative array and that would store or sort by value and I could go and of course I'm gonna have to put me info inside of there and also I would be able to sort by my key by just putting a K inside of there you're also going to be able to come in here and type in a are sort and K are sort for descending if you would like to sort in descending order we're also going to be able to have multi-dimensional arrays so let's go and create customers is equal to Raye and then you'll put an array inside of an array which I actually kind of like how this works versus how other languages create multi-dimensional arrays and then you put a comma and then you put in another array and let's say that she lives at one to two main there you go now you have a multi-dimensional array now let's go and say we want to cycle through it what I can do is say that I want to get my rows you're gonna see more about four loops here in a second but basically what it's going to do is it's going to start off creating a variable with a value of zero and it's going to continue to cycle as long as Rho is less than two and whenever Rho gets a value greater than two it's going to stop we're going to increment this and then we're gonna do pretty much exactly the same thing for our column so just change this to call them and everything else will be changed to call them as well as we go through here and then after I have all of that set up I can just go echo and customers and say that I want to do with the row and the column and then let's say that I want to go and have all of this information divided up with commas do it like that probably a nice idea to tab that in and then after each one of these I could just go echo and throw a break statements inside of there reload it and you can see all that information let's do some more stuff you could also turn a string into an array so I'm gonna say let letter string is equal to and I'm gonna go a b c and d it's very important to have spaces otherwise you won't know how to break this information up or you can have commas you just anything that separates then what you do is say explode and you're gonna define first how the information will be exploded and that's gonna be based off of spaces and letter string now we can come in once again and say for each letter array as and I'm just having this assigned to L and I'll use printf air again and I can output the individual letters this is gonna be a string break and then I'll say that I want to uh put the letter also on top of that you're gonna be able to turn an array into a string so let's go letter string two is equal to and you're going to use implode here we're going to just decide that we want to have spaces between all of our information and we're gonna use the letter array to convert from an array to a string and now I can come in and I'll put that information as well which is going to be our letter string to we're going to be able to come in and check if a key exists so we can say print F and he exists throw a D inside of there and then we will say array key exists and make sure you spell array correctly and then what we can do is what we're searching for which is going to be name and the array that we're searching for or searching through which is my me info and then once again we're going to be able to check if a value is inside of an array let's just copy this and I'm just gonna say in array in this situation and this becomes an array and I'll search for joy inside of my friends array to see if she is my friend or not and there is all that information and of course the one is represented with a value of true all right so there you go and I said I was gonna talk about loops so let's talk about loops now no you already saw a little bit about for loops I'm gonna show you some more but first I want to talk about while loops basically a while loop is gonna execute as long as that condition is true and one thing that's special about a while loop is you're going to have to have the thing you're checking for outside of your loop then we're gonna say let's say we want to cycle as long as I is less than 10 again curly brackets and then let's just echo out values I'm gonna put the plus sign in the front so that it goes it's actually going to increase the value of I first and then print it unlike what you saw previously and then I'm just gonna put a dot here and a comma and then after it goes and cycles through all those we are going to print out a break statement for loops on the other hand as you saw are going to compact everything down into the one statement you also saw for each previously so I'm gonna do the same thing with a for loop except in this situation I will increment after and let's do some other things inside of here I'm going to say that I only want to print odd numbers and one way to do that this is something useful that you'll do and sometimes I'm going to say if the value of I modulus 2 is equal to 0 which would be every single even number would give you that meaning it has no remainder if divided by 2 I'm gonna say that I want to continue and what continue means is that I want to jump back up here to this loop which is going to increment the value of I and then loop again let's say that I want to break completely out of the loop if ever I is equal to 7 well I can just go and put break here if you're going to do a single statement after an if so you don't have to use curly brackets by the way and otherwise I'm going to say that I want to print the value of I and again I'll separate with commas and then also I will put another break statement here and if I run it you can see exactly the output that we receive I talked about for each to show how it is easy to cycle through arrays with it so I'm not really see any point in covering I'll probably do something with for each later on and then tutorial but you already saw it so you know what the heck there's also the do-while which is guaranteed to echo or execute at least one time all of the code between the curly brackets so I'm gonna say do-while and just a value inside of there and just to prove that it is gonna work I'm gonna say while I is greater than 0 well guess what in this situation just to start off I is already equal to 0 so this never execute except to do wild guarantees that it will and you can see that it does and you also saw how to cycle through a multi-dimensional arrays so I don't really see any point in going more into looping at this point of course it'll come up as the tutorial continues but instead I want to talk about functions now functions are going to allow you to reuse your code and a function name must begin with a letter but it's also going to be able to contain numbers and underscores just like variables and how you create one is you type function and let's say I want to add numbers and I'm going to receive this is called a parameter number one so this is going to be a value that is passed to this function however I can say something like if a value isn't passed I want to assign a value of zero to it so it's a default value of sorts and then I can also define another value that's supposed to be passed and also give it a default value of zero then what returns going to do is return whatever we put after it so if I say I want to return the result of adding these two numbers together that's how you do it then I'm gonna be able to come in here and say something like five plus four is equal to get that value and then call for the function to execute and it will return a value that I will then put where I have the % and the D and I'll put five and four inside of there run it and you can see it works alright so that's a basic function don't worry we're gonna get into more complicated things one thing that's important to understand however is that by default function are basically attributes that are passed two functions are passed by value and let me demonstrate this I'm gonna call create a function called change me and I'll have changed be a parameter pass to it and I'm gonna say that I want to get the value of change and change it to ten now outside of this I'm going to create change and give it a value of five then I'm going to call change me and pass change inside of it and then what we're gonna do is see what the value Changez after we called that function now you might think that it would be 10 because that's what it assigned but you would be wrong so let's go and say change and you can see it remains 5 and like I said but the reason why is it passes by value which means change isn't passed inside of here 5 is passed inside of here you will however be able to pass by reference which means a reference to this actual variables place in memory just by making a slight change to your function and you just go up here and put an and Sun inside of there and now run it and you can see that we were able to change the value even though it resided outside of the function you're also going to be able to receive a variable number of parameters so let's say we had a function called get some and we didn't know how many values were gonna be passed inside of it we just go one two three like that and let's call this noms this is going to convert everything passed into it into an array then we could say sum is equal to zero and then for each say I said there would be more looping involved nums as num and we can go and get the value of sum plus equal to whatever the next num is and then after we're done cycling through that we can use this K return sum then outside of our function we can say printf sum is equal to and going output that value and they call our function get some and no matter what you know no matter how many values you put inside of here it's just automatically gonna work so you may say well that's how you get an unknown number of values or a variable number of values how do you return multiple values create a function again and I'm gonna call it do math it's gonna get a value of x and y and what it's going to return is both a what happens when you add these values and what happens when you subtract these values so it's gonna return both of those so how does it do it well simply it creates an array and goes X plus y and then X minus y put a semicolon after that and then what we can do is we can say list sum and difference which is going to create those two variables for us call do math with five and four passed inside of it and then we'll be able to come in and just say echo sum is equal to whatever we said the sum is and do the same thing for the difference pretty neat stuff so difference and difference and there you can see we got those as well but wait there are so many other cool things we can do let's say that we would like to apply a function to every single value in a list how would we do that well we can say go and create a function and it is going to double whatever is passed to it so we'll just say return and x times X or it'll multiply everything times itself all right so there we go then we're gonna create a list and one two three and four now we'll go and create double lists and how we do it is with map and it's called array math and we pass inside of it the function that we want to call which is called double and then we passed inside of it the list that we want to have a ray map operate on another thing that's neat is let's say you wanted to print a human readable version of list you could use print underscore are doing my best to cover every single thing and you could do that and if we run it you can see that it prints out that array and that we were able to double all of the values in the array so neat stuff so we can go and perform the same action on every single value what about being able to reduce values into a error in an array into a single value so what I want to do this time is multiply each value times all of the other values so I'm just gonna change the name of this to malt from multiply it's going to be X & Y which are going to be each value inside of the array so the first value and then the second value then we'll switch up and that value move into the axe and then we'll have the third value and so forth then we're gonna come in and just go like this and then change this to Y good like this and then return whoops return X so this is a little bit more understandable what's going on I'm gonna leave my list right here and I'm gonna change this to product prod and we'll call array reduce and here we're just gonna switch these up a little bit here we're going to first list our list then the name of the function we're gonna call and then our default first value and then change this to prod right like that run it and you can see it multiplied every single value times every other value in the list in order from 1 2 to 3 to 4 all right so now why don't we go and take a look at how we can filter values as you remember before I went and checked if values were even or not why don't we go and create a even list so I'm gonna call this is even and just get one value here cuz it doesn't make sense to have two and then inside of here I'm going to say return so we can just get rid of this return throw a parenthesis inside of there and then say modulus two and check if that is equal to zero or not and then down here let's call this even list let's get rid of that let's go and put another one inside of here so this is gonna be even list is gonna be equal to get rid of this all together and we will call array filter pass inside of it the list we want to work with and the function that we want to have operate on our list items and then here we'll just say we want to print or even list after it's done and there you can see just have the even values so neat stuff a whole bunch of different ways to work with functions and you'll see more later but now I want to talk about dates all right so when we're working with dates you're probably gonna want some time zone information in regards to how PHP works with time zones so just go to php.net for / Manuel en timezones the PHP alright and let's go and do some stuff alright so what I want to do first is set the time zone that I'm working with and that's going to be date default and time zone and set and that's gonna be America in my situation underscore York then what I'm gonna do is show you a whole bunch of different ways to format this information it's gonna be quite repetitive so I'm gonna say date and then after this I'll call date and I'm gonna throw an I and F M - D - why let's go and get to the all the values and then I can also get time information and in regards to where all this comes from you'll be able to experiment with it just by searching for PHP function date and you can see the URL right there and here are all of the different character codes you can use to represent your date in pretty much any way you could ever possibly imagine I'm gonna show you some some types with this output that I provide here now not only are you gonna be able to work with the current time but you're also going to be able to create specific times so I'm gonna put the most important date in history inside of here make time and I'm gonna go 0 0 0 and 12 21 1974 and then I can say once again echo why don't I just get this right here echo and we'll put important date and then follow that up with import date whoops change this to lowercase and run it and there you see your information and the 0 0 0 by the way just represents the very beginning of the day so you know first thing alright so there is a lot of information about dates now I want to show you how you can include other files inside of your PHP code so I'm gonna create a function here called say hello dot PHP and this is going to me to go and create PHP code in a separate file that I can just at will just throw anywhere I want and I'll just say hello right here called say hello that sounds like something good to do with it jump back over here now anywhere I want that code to show up all I need to do is go include and say hello and make sure that it's in the same directory as this that's it that's all I need to do boom and there hello shows up so neat stuff pretty simple to include additional files and now I want to talk about exception handling now we are going to use exception handling it to basically keep our program from crashing if the user does something crazy all right and what we're going to do here is we're going to handle if the user tries to divide by zero so I'm gonna say this receives a value of whatever some type of value and I'm going to say inside of here if number is equal to zero well then I want to throw a new exception and say inside of it the message that's going to be displayed on the screen you can't divide by zero and then down inside of here I'm gonna say otherwise return calc is equal to 100 divided by whatever the number is so I knew that I couldn't have them you know send me a zero so what I did was I provided output instead of a complete program crash now what I can do is inside a try block is where you're gonna put any potentially problematic code that could throw an error well in this situation I'm gonna have bad divide and I'm gonna throw a zero inside of there then what I can do is call catch and in this situation catch is going to accept any exception that would occur and whenever it does in this situation rather than crashing it's just going to print out my custom error message that I defined and I get that custom error message if I learned how to spell message our message there we are right like this reload and you can see instead of having a blob of you know mass pop up on the screen if it just simply says you can't divide by zero it's a nice graceful way to handle that error all right so there is a lot of the meat and potatoes of the PHP programming language and now I'm going to get more into in working with input from the users interacting with databases and such alright so whenever it comes to working with PHP especially with databases or if you're just storing files and such it's very important to sanitize the data coming in so I created a new file called Tut to dot PHP and here's just some basic HTML it's a post version of a form and you can see the output on the right side of screen it's not pretty but I wanted to keep everything very very simple here so you can pause your video and type that in or get the code that is in the description all right so let's go and sanitize this first thing I want to do is check for a valid email so I'm gonna say if is set and I'm using post this time like I said so I'm going to say post email and that's an array by the way so if it is set now what I want to do is use filter input to make sure that it's valid now you're going to be able to use filter input with input get post cookie server as well as the environment variables so I'll just say if not filter input again I'm using input post and I'm specifically checking email that is being passed inside of it and then I'm gonna say that I want to validate that this is indeed an email and the message I'll print here in this situation is that the email isn't valid and then I wouldn't store it I wouldn't touch it I wouldn't do whatever I wanted all right else if this comes back I can then say to make sure this is a break statement throw this in and say that it is valid so they got that all set course I have to throw my PHP tags inside of here and close that off then I could go and throw an email inside of there and hit submit and you can see it's valid however if I type in something that isn't valid you can see it comes back as isn't valid all right so that's one way to check if an email is valid or not and you're gonna see way more as the tutorial continues I can also come in and verify if these numbers here are actually numbers how I can do that is I'll say if is set and post is what I'm checking again and I'm gonna check number 1 which of course is coming from up here see number one number two that's where those are coming from and then I'll say and not empty and again check the same value post in this situation I'll do number two so two different ways of checking then I'm gonna say number one is equal to and I'm gonna call filter and put again again input post and number one is what I'm working with this time and here what it can do is filter and sanitize and make sure this is a float and then also I'll say filter flag allow fractions and I'm gonna do the same thing for number two so it will sanitize both of those number two and change this to number two and then what I can do is let's say here's another thing that I haven't covered this is s printf and what it is gonna do is return a formatted string so I can come in and say that I only want this to be one decimal place + and again one decimal place is equal to 0.1 F and then go and throw in those values whoops make sure I put dollar son number one number two and then number one plus number two and another thing we can do is escape output so that we can eliminate any special characters that might be inputted so that you know like a cross-site attack or something like that would be attempted on our site we can go and get rid of those I'm going to show you that in another thing but I'll go output show you that in a another example that will allow you to see better what's going on and what the heck went on I do some more stuff here I'm also going to show you how to validate a URL so I'll say is set post and I'll check the website that's being passed inside of it and how you're gonna validate that I'll say website is equal to again filter input input post what am i checking I'm checking the thing with the name of website and I can use filter validate URL to see if that's valid and again I can go and get this that checks out and maybe I'll go input website here and then throw a website inside of here to see if that checks out and going input some information and I got an error because I typed in fractions instead of frac a fraction and here whenever I went and checked this the email came back as working and the numbers all work the website didn't let's check this and if I run that you can see there is our sample output and I'm gonna show you more later on but if you want to see all of the other different validations that are available you can just go to this website right here or the sanitization filters let's just go like this you can actually see them you can find those at those addresses alright so cool stuff and I said I was going to give you another example so you can see how HTML special characters work so I'm going to do that now so what I'm going to do here is go HTML is equal to a H reference is equal to hash and close that off and just type in sample and create a link like that then I'll say echo HTML dot and throw a break of course then what I want to do is convert the special characters to HTML so it can be displayed so I'll say echo HTML special characters con HTML throw another break in there and then what I'm going to do is strip the tags so I'll say echo and let's say that I want to strip all the tags except for you know in our HTML that we have there except for the a tag just throw the a in there like that and then you can see some sample output and then I can also eliminate all my tags by saying strip tags again throw the HTML in there and another break and then just print that HTML out and there you can see those four examples of how we were able to go in there and sanitize this HTML or what happens if we did not alright so cool stuff and now what I'm gonna do is show you how to set up a database and then how to interact with the database with MySQL and PHP so now I'm gonna set up the database and you either go to localhost colon 8080 PHP myadmin or local host PHP myadmin and I show how to set all this up in the installation videos that are in the description and I'm gonna log in as root and this is what you're gonna see all right so what we're gonna do is create a new database so over on the left side of the screen you're gonna click on new and we're gonna call it students so just type in students right here and then click on create now what we're gonna do is create a table so we're gonna type in students and we're gonna need thirteen columns for this completed table and then type in go or click go whatever you do this is gonna pop up and then we're gonna put in all the information that we want to store on all of our students so I have everything right here let me just zoom in what we're gonna do is we're gonna put first name and that's gonna be a variable number of characters and I have a link also to a MySQL tutorial but if you don't want to watch that that's also in the description that goes into detail but if you don't want to watch that right now you can just do all this it's pretty easy to understand most gonna have last name and again variable number of characters this is like a string a variable number of characters and a length of 30 email again 60 street 50 you can pause your video if you want to type all this in we're also going to have a city which is gonna be 40 characters a state actually go in and make this a variable number of characters and two zip code medium int phone variable number of characters 20 birthdate that's just going to be a date we're gonna have sex which is going to be an enumerated type which just means it's going to be a list of potential options which is either gonna be male or female date entered is going to be the date in which the student information was entered make that a timestamp lunch cost is going to be a float and then student ID is going to be an integer you're going to want to mark that as unsigned inside of here and you're also going to want to mark zip code as unsigned right here for attributes you could also see over here under state I put as defined and Pa that just means that that is going to be the default PA Pennsylvania that's where I live you're also going to notice here that for is it possible to have null characters I have this all marked as none that just means that it's required that a value must be entered and I put a check here for date entered and lunch cost meaning that those could be marked as null then under student ID down here you're gonna click on this and click on primary and that is going to be under index the index column right there whatever you do this is gonna pop up just click on go and that's gonna be your primary key which means it's a unique key that every single student will have then you come down in the right-hand corner and click on save this is exactly the same on Windows and Mac whatever you do you're gonna see the table structure is exactly as you see right there and you're also going to see that Stu table is over here under the students database now we're going to click on SQL and we're going to enter a bunch of student information so you're just going to type in insert into students which is the tables name and values and then put everything in order based off of the order that you listed all of the different items down here where it says date enter just put in now and it'll automatically go and put in whatever the current time is and null right here is for student ID and the student ID is going to be auto incremented so it'll automatically be created then come over here and click on go and you just inserted your first student into your database now I'm going to enter a whole bunch more students and I'm gonna have this also in the description a link in the description you'll be able to go and copy this and paste in all this student information and after you go and cut and paste or type all that in whatever you want to do just click on go and all that information will be entered then you're gonna click on the SQL tab once again and if we type in select star from student where one that is saying that we want to go and get all of the student information and if we do we're gonna see everything is right here everything that we entered go and click on the SQL tab again and this time we're going to define a class which is just gonna be an identification number and a name so you can just go create table class and then it'll be whatever the name of the class is again variable number of characters 34 a string it has to be a value or a value needs to be entered that's what's not in all means and in class ID is just going to be a primary key or a unique number that it's going to be associated with this name and after you enter that click on go and you can see that that was created and you can also see classes over here on the Left right here and then I went and added in a whole bunch of different class information again the null value is for the primary key and whenever you put in null for a primary key it's automatically generated and its unique after you enter all that click on go and you can see that was all entered and we're going to create another table right here called test it's going to have a date inside of it's going to be whether it's a test or a quiz it's going to have the class ID associated with this test and a unique primary key that's Auto incremented that is required that's going to be automatically generated each time we enter test information once again click go and everything will be set up and I'm gonna go and create another one called score and this is basically I'm not gonna use all the stuff in this database but it's gonna set up a system that's going to allow you to go and experiment with PHP mi SKU all even after this tutorial to learn even more that's why I'm bothering to go into all this again this is going to be recommend store scores on tests so you'll have a student ID and event ID a score and then a primary key which is actually going to be a combination of the event ID and student ID and then click on go and you could see that that went and create was created for us and you can see all the different tables that we've created so far again create era click on SQL tab type in absence this is going to record any student absences again student ID the date of the absence and then primary key going to be based off of the student ID and date and click on go that was entered properly you can always come in here and get all of the results from any of the different tables just by going select star from and whatever the table name is and then go and run that if you ever need to alter a table in some way you just type in alter table whatever the tables name is and what I want to do in this situation is add something called max score again it's an integer it must have a value and here I'm saying that I want it to get placed inside of the table after type again click on go that was entered properly and you're gonna see that all that information is inside of here I'm gonna go and enter some test information so insert into test and these values that we have right here and they must be in the same order as the table information once again click on go that's entered also I'm going to go in here once again and alter the score table this time and I'm going to say that I want to change event ID into test ID it's an integer on not null here you can see it's a Venn ID and then I'm gonna click on go and now you can see it's test ID all right so that's some different ways to mess around and change things in our database then I'm gonna go and enter a whole bunch of scores like I said we're going to you can just go and get all the stuff and copy and paste it inside of there those are all the scores for all our students on all the tests and there is the entire list of all the scores but like I said it's better just copy and paste and I also entered in the absences and once again this is just going to be the student ID and whenever the date was for the absence and then I hit go again and that was successful as well you can tell it's successful because it says three rows inserted and we meant to insert work three rows just to cover a little bit more about working with MySQL let's say that you decided you wanted to name all of your tables instead of absence two absences and instead of class two classes and scores score two scores and so forth and so on well you just say rename table and then list all those different things you want to change and then click on go and then you can come in and go and get all of the different information on all of the absences click on go again now what we're gonna do is go in here and create a new user so to do so just click on user accounts and I'm gonna call this users student web I'm gonna say that they're gonna operate on the localhost I'm gonna type in a password that I can remember I'm going to say that I want to grant all privileges on database students which is the database that we're working on then I want to scroll down and I want to say that I want to give this new user the ability to select insert and update information in our database after I do that come down here and click on go and that user is now going to be able to do all of those things and after you do that you're going to be able to proceed on to the next part of the tutorial where we are going to allow you to go and get student information and then eventually update and delete and do so much more so I'm going to be going and printing out information from the database into a table and this is a file called main dot CSS and it's just some basic styling your screen and create that file very basic styling and you can see right here exactly what that is going to look like whenever it's set up so it's just black and white very very simple then we're gonna have a form down here that's gonna allow the user to insert new student information let's move out aside here for now so there is main dot CSS then I created in another file called DB underscore connect dot PHP and this is going to be the file that's going to be used to connect to our database so again we're just going to have our PHP tags and what we're going to do here is create a PHP data object to work with our database and we're going to create constants a for our user that's gonna login and it's going to be student web this is the user that you went and created just a couple seconds ago and we're also going to store the password inside of this file so I'm going to call this password and the password I'm using is Turtledove please don't use this Isis my password I use in all my tutorials and there's a chance that it could be on a list so I'm left to search for so just don't use it use some other password just remember it then I'm going to define my datasource so just come in here and we're gonna type in my SQL and host is equal to localhost and by using PDO which is what we're gonna be using it's going to allow our PHP code to actually work with multiple different databases but of course I'm gonna use MySQL here because it's what's most commonly used and you just list your database name which is students alright so we have that defined now what I want to do is try to connect to the database whenever this file is called and we'll go DB equals new PDO like I just mentioned a second ago and what you're gonna pass - it is DSN which is gonna say that we're using MySQL localhost and the database name students and then you pass in the user ID as well as the password and there it is now if we had some sort of problems with that here is going to be exception handling again what I want to do is catch that air and it's going to be a PDO exception and how we're gonna handle this is go error and message is equal to and we're actually going to have this handled on a separate page which we're gonna create here in a second go and get the error message and then I'm going to include an outside file that I'm gonna create like right after I'm done with this it's gonna be called DB error dot PHP and it's gonna jump to this file and go and output some new information and then after that we can exit from our database and that's all we need to do there now let's jump over to DB error dot PHP and it's gonna be this file right there and you can see right here just basic HTML just like we had before I'm going to print out database error and then to actually go and get that database information which is the message that was sent over to this page inside of PHP tags whoops I don't know why I did that PHP I'm going to just print out our error message so error just just makes for a very nice place for me to continually send all potential errors that I get no matter where they occur and there you go that's all you need to do and all those messages will go there and automatically load in database error now I'm gonna jump into a file called Tut three died PHP and again you can see basic HTML that we have here language there is a link to our style sheet which I just showed you a couple minutes ago then we're going to have student list which you're gonna see right here so you student list there that is we're gonna have a table that is gonna have all of our information about all our students could pause your screen type it in or go and get to the code that's in the description I'm gonna load all of the information using PHP from our MySQL database inside of our table and then you can see here where we are providing for the option for them to enter new student information and to create a new student and we're gonna go and sanitize all that data and work with it and you can pause your video like I said or go and get it so there's all that information just like that and there it is I'm going to jump to the top here though I'm gonna go in and connect to my database so there's my PHP tags and to connect to our database I'm just going to say require DB connect dot PHP this is the file that we just created and what I want to do here is get my student names and to do so you define a MySQL query and basically just run it so I'm going to say query students is equal to and select is what we're gonna use to get all of our student names and star means I want all of them from the students table and I'm going to say that I want to order by the student ID so there is the query it is exactly the same as a regular MySQL query now we're gonna use prepared statements to execute all of our queries and this guy right here is going to create a P do statement object I'm going to call it there we are student statement and it's equal to our database and prepare and Cori students and pass in that query that we have then to execute our query I'm just gonna say student statement paste that inside of there and execute then what I want to do after is you that is I want to return an array the that is going to have all of the results or all of our students I'm going to store that inside of students again students statement a little arrow and we'll call fetch all and I'll be getting into object we're in a programming the PHP in a little bit so you'll understand a little bit better some of those things do what the arrows mean and such then what I want to do is allow a new SQL statement to be able to be executed so I'm going to put students statement again and how you do that is you call closed cursor and then we'll be able to issue more queries all right so this is just basic HTML that you see right here so I'm going to come down inside of here and then right here is where I'm going to fetch all of the student information that I just asked for so I'm going to tab here again PHP and then inside of it I'm gonna go TR actually I'm gonna do this in a slightly different way let's go and put this all in one line what I'm gonna do here is I'm actually just going to call for each of the students inside of there using for each so I'm going to say for each students that's the name of our array as student and we're going to be able to access all this information put a colon right there and then after this I'm going to list out all my table rows and get all that individual information so I want to print out all of the individual column data so I'm going to go TD and PHP echo and students and student ID if I want to get that information just use the same name as I use in my database and make sure this says echo put a semicolon there and then close off that tag and then close off this tag alright we're gonna be doing pretty much the same thing for every other piece of student data that's in the database let's go and grab it so this is going to be first name so just first-name exactly like you had in your database and this is going to be last name and you know what let's do something a little bit nicer instead of oh why is that listed as that whatever oh let's just get rid of it alright so instead of doing first-name and lastname in individual tables like I said here name so what I want to do is actually combine these so I'm gonna say first name colon put a space inside of there colon and then student and then this is going to be last name inside of here like that and then it closes off and then I'm gonna copy this guy right here that's gonna put them all in the same box I'm also going to get the email and the street and the city and the state the zip code and phone number and I'm just putting in all the same exact as we have with our database way of referencing this stuff birthdate underscore date and the sex of the students and the date entered and then finally lunch cost so lunch cost and then too and this I'm gonna put in TR to close our table row and then after that I need to mark the end of my for each loop by saying PHP and for each semicolon close that close that and that's just the for each block is this guy right here and that's just the end of it and that's all that I need to do and I have a little error which is set in line 4 and we can see I put equals in there two times all right and there it looks like it works so there are all of the students that I entered into my database and all of the information looks like it's all good and here we have the ability to enter a new student and let's just move this over here and you'll see up next I'm actually going to create a file called add student PHP and grab all that information sanitize it and store it in my database all right so now in add student dot PHP I'm going to handle some pretty serious validation of this data that we're gonna get here where they try to enter a new student so type in PHP of course then what I want to do is get all of my data that has been input so I'm going to say first name is equal to and I'm gonna use filter input here just like we have previously and it's post so and what we're specifically getting is first name of course and we're going to validate all of this information so of course I'm also going to do the same thing with last name if I can there we are and this is last we're also going to get our email so change this to email and change this of course to email and I could go and do the validation with the email like I covered previously but I'm gonna show you how to use regular expressions to validate email and let's get Street and we're gonna do this for everything else so city and city state and state zip code and zip code and phone number again we're going to validate all of this birth dates and birth date sex and sex lunch cost and lunch cost and then I'm also going to create a time stamp for whatever now is I'm going to call this date entered and how you do that is just go date and then we're going to say year month day hour minutes and seconds and now what I want to do is verify that everything has been entered so I'm gonna say if first names I'm showing you multiple different ways to verify data I'm positive I'm gonna get comments that say you're but I'm trying to show you every way of doing things that's my thing I try to show you everything that you may ever see so that whenever you see it you'll understand what's going on and now we're properly verifying data here for the first time and city also inside of here just verifying that null that you know that there actually is a value for all of these things state same thing and zip code as well and phone sorry I thumb up eating myself but kind of have to otherwise you can just watch the whole thing hit pause type it in or you know get the code whatever you want to do birthdate sex and lunch cost and that's all Wellman actually changes the lunch call us changes the false alright so we got everything here now if this comes back now what I'm going to do is print an error message here in this situation so error just like we did before and then I'll pass it to our error page that's gonna handle it and I'll just say all values not entered and let's throw a break inside of there cuz we're gonna have other error messages that might pop up and just like we did before we'll say include DB error PHP to get that page to open and now what I want to do is use regular expressions that are going to validate the information further and I'm gonna do this outside well it's gonna be as an else if clause and regular expressions if you don't know are just the codes that you use to match patterns so for example I am I'm not gonna get too far I'm gonna show you examples of regular expressions but I'm not gonna get into tons of detail about them because I could do an entire hour and a half long tutorial and I have just on regular expressions but basically what you do is you're gonna say preg match is the function you're gonna use and then you're going to define with a forward slash everything you're going to accept so for first name what i want to say i want to accept and i'm you're gonna put the things you're gonna accept inside of brackets I'm gonna say I will accept letters A through Z lowercase letters A through Z uppercase and that's it and I expect the first name to be between 3 and 30 characters in length and then this dollar sign signifies the end of the string and that closes off that regular expression and then we put inside of here what we're checking so I'm gonna say first name is what I want to check and that is how that operates so if not that's what this is so if it doesn't match that pattern what do I want to do well I'm gonna go and get our error message here and print that out on the screen that there's something wrong with the first name so I'm gonna come in here and I will say first name not valid and everything else is exactly the same and then we're gonna do another else if after that and for the last name I'm basically gonna do exactly the same thing so we'll just put last name inside of there and then I'll change this to last name so last name not valid again we're gonna do the same type of thing for our email and I'm gonna save some time here because I'm actually going to use built-in stuff to verify the email so I'm gonna say else if and get rid of this thing right here and instead say filter variable and I told you where to find all these earlier in the tutorial series and let's just go and get rid of all of this excess stuff right here and inside of this guy I'm going to put email and it's going to go and verify it for me so I'll say validates email all right so there we are and then I can say email not valid if we have some type of issue with that and then we can do another else--if and this one is going to pertain to the street being valid and I'm gonna use a regular expression in this situation so let's just change this to street and then I have to create a regular expression that's gonna match for my street this carrot symbol here can vera is going to represent the beginning of a string and this represents the end of a string so I'm gonna give you a little bit of a tutorial on using regular expressions here I'm also gonna say that I can accept numbers 0 through 9 I can expect or I can accept spaces I can accept commas I can expect or I can allow hashes I can allow some types of single quotes for example and also I'm going to say that I can allow periods all right so we got all those different things inside of Erin here to say that I'm going to allow up to fifty characters inside of our streets and that's pretty much everything's fine there so I can say here Street not valid and then we'll go and do another one so throw this inside of here now what I want to check is the city and see if that's valid or not so I'm gonna come in here and I'll say City and I'm the only thing I'm gonna have some issues with is if there's any type of odd symbols but you know I think you get the gist of what's going on here put some spaces inside of there and we can say something like two through and I think the biggest city that I know of is fifty eight characters long I think it's only ignore way or something so there that is and that's City and I can say city not valid and they'll do another one so what else do I want to check for I want to check for states and this one's actually gonna be kind of crazy alright so what this is going to do is match the beginning of a string again and then it's going to go through and match any A's that are followed with KLR and Z or any C's followed with a ot or and I think you get the gist of it and this is going to verify two digit state representations alright and that's basically what that does and that's going to be 0 or 1 or is or 0 or more and this guy here is going to represent one or more of what follows so that's what we got for verifying our state's I know it's a little bit crazy what else we going to verify here well I'd like to also verify zip codes this is gonna be a really simple one so let's go and close this off at the end so I don't forget that and this is going to be zip codes and for zip codes I'm gonna say that I'm going to accept just 0 through 9 and I'm going to accept only 5 numbers and that could cause some issues if they put a you know spaces on the side of there but whatever this is just a basic overview so that you get the gist of how to do the stuffed and that should be good and what else are we gonna do let's go and close that off I'm also going to want to verify telephone numbers and telephone numbers gonna be a little bit weird here as well again we're going to say that we're going to accept parentheses and numbers which is going to represent the number one right here then we're going to accept like dashes and spaces and dots and we're going to accept a parenthesis here they it could be one of those things but we don't necessarily have to have them then we're gonna have three digits and then we're gonna have three more digits again we're gonna accept dashes spaces and dots and then once again four digits after that and that is the gist of the telephone number definition birthdate is going to be rather simplistic I'm going to say that I am going to accept just a certain number of digits as well as dashes and spaces so I'm going to say that I will accept zero through nine obviously and then I'm also going to accept dashes and I'm going to accept spaces and I'm going to say that this is should be something like eight to twelve in length and then change this birth date and there's birth date and in here we can say birth date not valid and we're almost done with these guys what else are we gonna verify we're going to verify sex so for sex I'm going to put sex inside of here and for sex I'm only going to allow either the characters M or F so I can come in and say M F and M F and this is only going to be one of those is what I'm accepting and otherwise I will say sex not valid and that's basically it and after this after we make it through all those what I can do is try to insert the students into my database so I'm going to have to go require once just make sure this only loads one time and this is gonna be used to connect to our database just like we connected to our database previously and then I have to create my query just a MySQL query again and this is going to be an insert query insert into the students table and then I list out all of the individual things that I want to place in there and this has to be in order so this is gonna have to match the values that you're gonna see here in a minute in order if you put them out of order you're gonna get errors so streets and city and state and zip code and if you may just made it this far in this tutorial please take a second to tell me in the descriptor in the comment section because sometimes I feel like I'm talking to myself so sex and what else are we gonna do here date entered is going to be another one and lunch cost is going to be another one and students ID is going to be the final thing and then after that what I can do is I'll say values and then the values are going to be placed inside of here so you can say values and then I'm going to list out everything so I'm going to say first name again everything's gonna be exactly the same as what we had before so I don't I just copy all of this stuff right here and go in here and paste it inside so there's all those and then all I need to do is put a colon in front of every single one of these and all of this information will be transposed from what we have then verified above what has been verified up above so : : : and these are going to add all of these parameters to my statement okay so there we go got all that set up and we got our quarry all set up now what I need to do is create my PDO statement object and I'm just going to call this STM and we're going to go and get our database and prepare our query with prepare and there's our query there we go and then I need to bind all of my values to these parameters that are right here what I defined so how I do that is go STM and then bind value and and then we'll just list them all again so a lot of the typing the same stuff over and over again and first-name and we're gonna do that for every single value that we have again so we'll do the same thing for last name and last name and email email streets and streets and city and city and states and your guess is right states zip and zip phone and once again phone birth date and birth dates sex and sex dates entered and you remember that we created this one based off of whatever the current time was we're also gonna have lunch cost and I set this up on purpose so that there's a lot of additional things you can practice with with this database and students ID and for the student ID actually what I'm going to do is put an all inside of it so I'll say null and then what you do is you say PD o per Ram and this is an integer after you have all of that set up then you need to execute this query and then I'm also going to verify if the query was successful because this function is going to return true or false based off of if it was successful or not something you don't necessarily have to do I just want to show you what it looks like so you call execute it returns true or false and then we need to close this so that we'll be able to go and issue other queries if we would like to close cursor and then after that what we can do if an error occurs we can print the error so I'm going to say if I'll show you how to do that as well now you would probably display this in a nicer way but I just want to show it to you and keep everything as simple as possible I'm gonna use print R again so that we can just go and print this information out this is actually an array that's returned error info and this is an array so I want the second part of it which is the main error message and that closes off that part then I also want to display all the student information in the table so where is that require once there it is let's go and get this and down inside of here outside of that so I'm gonna go require once and I'm gonna go and query the students and again select everything from students order by student ID and we'll be able to put those in that table and I need to prepare this so once again student statement call execute on it go and get our students array by going student statement and call fetch all on it to get all of those results close the cursor so we can issue other queries and that's it and I think just about every single thing else here is going to be ok this is going to be the table where we go and get that information and I'm going to jump over into tuck 3 and steal this and Nations this is gonna go and get all that information from our database and put it in our table so I'm just gonna copy that jump back over and add student and paste that inside of here there that is then as far as I know that should be everything we need and I went and entered some information inside of here and let's see if it works and we have an error here on line 65 I knew after all that code there'd be something wrong so let's go to see line 65 I need to put two colons inside of there see if that's okay now reload and it's gonna say yes I want to resubmit database errors all values not entered what was wrong with that let's see if there's something else going on here undefined variables student statement on 74 I probably forgot a dollar sign and no I didn't a couple little errors here forgot to put from inside of there and then I forgot to go student statement paste this inside of here and then I need to go and prepare my statement so database prepare and then query students inside of here there we go and that's let's test it again and reload it and all values not entered is the error message I got let's try it again I think I have everything entered here let's go add student all values not entered hmm and I see that I put last name and correct little bug and let's just test it still all values not entered ah this guy right here should be lunch so let's change that to lunch and actually on top of that I'm gonna filter it to make sure it is a float so filter validate float and try again still not working try again reloading the page this is actually birthdate inside of the form HTML that's what caused that error and let's give it another try and it looks like it worked all right so sorry about all those errors but we finally got it to work and everything looks good and you can go and test those validations by putting in improper information but I'm certain that the work alright so now we learned how to add students now we're gonna learn how to update students right so for update student dot PHP I'm basically just gonna copy add student and go and change a couple things one thing I need to do is provide for the option to get to student ID and I am just going to name this student ID and I cut out the validation with the regular expressions obviously in the real world you would keep those in so but I just did it to make the file size a little bit more manageable and I want to verify that this is an integer and of course I am going to need to verify that they entered a student ID here because that's how we're going to allow them to change it so I'm going to say student ID equal to null and right here is where I cut out all of the verification and the regular expressions definitely go in there and keep those in though alright so and I'm going to create a new query that is once again just a my SQL statements so students so I want to update my students table and then what you do whoops what are you doing here so students like that and then what we're going to do here is I am going to say I'm gonna come in here and I'm going to say set first-name to be equal to first name again and adding those parameters and then I'm going to do that again for all of the different inputs except I'll just say last name like this equal to and last name and do that for all of the other different pieces of data that we're working with so email Street city state zip code phone number birth date that's birth underscore date right yes and birth date again sex and lunch cost and then finally whoops I'm not gonna put a comma there finally I will say where whoops make sure there is a space here after that however where student ID is equal to student ID if we get an error it's probably gonna because of spacing or something inside of here but we can easily fix that all of this is going to be the same we're going to prepare our query we're going to validate all of this information as well as bind those parameters student ID down here instead of going and generating a new student ID we are going to instead have it be the provided student ID again we're going to execute that close the cursor so that we can issue further ones handle any errors and output them on the screen we are then going to go and get a student list so we can populate a table with it again all the generic HTML here's the student list table that has all of the students listed cycle through the students print them out inside of the table just as we did previously I do do I have an ID inside here yes I have ID right there and this does get the student ID and then the final thing I'm going to allow them to do is to delete a student so I'm just gonna add this form here I'm going to create a new file called delete student dot PHP it's posted and with this we're going to get a student ID and that's the student ID whenever they click the button it's going to delete a student so let's save that man let's see if it worked so update a student who I want to update is going to be Sally small so I'll just type in in 16 and let's change this from Sally small to Sam small just to do something and mail and let's just go and give them a generic birthday and there we go that is all that information let's try to update it warning and what did we do wrong line 49 and I'm just going to go in here and make sure there's spaces everywhere because I think that's probably what cause the air here this isn't gonna matter because this is all separated with commas but down inside of here where we have lunch cost I want to verify that there's a space inside of there see space and reload it see if that fixed it nope still got an error let's figure out what this is this is 48 still getting an error with this so let's figure out why oh I see I didn't put date entered because I would want to keep that the same as whenever the student was first entered so let's go get rid of this line right there save it reload and let's see if it worked and Sam small and everything else looks good alright so we got that all set up and now all we need to do is figure out how to delete students and once again this is going to be very similar and I call this delete underscore student dot PHP and we're gonna come in here and we're going to have our PHP code but we're only gonna get one input which is gonna be the student ID in this situation so we're not gonna have to type a lot of this information in here one thing that I do want to copy however is going to be this part right here so I'm just gonna copy that jump over into delete students again we're gonna have PHP code obviously we're gonna get the data input which is just going to be student ID there's nothing else going to be passed inside of it I'm going to say filter input and make sure that all of they all that they provided to us is an integer and that's going to be student ID from the HTML form and how we validate that is say filter validates and and again we're going to verify that everything's been entered which there's only one thing so we're just going to say students ID equal to null and in the situation that student ID is null we are going to print out our error message and else otherwise we are going to require once and this is going to be our database connection so DB connect whoops what that do connect dot PHP and then I need to create my query for deleting so I'm going to say query is equal to and delete from students and I'm gonna say where student ID is equal to and it's going to be our student ID and then I need to prepare this and let's just go to here and there's the query and prepare and then I need to bind a value to it so I'll jump back over here paste that inside of there there is our query and bind this is gonna be students ID and once again student ID and I need to go and execute that code and close it and so forth and so on so let's jump over into update again go after this and we'll go grab all of this stuff so execute the query print any errors and all of that and then get all the information for the student database so we'll come in here and right after that put this inside of there and I probably have an extra curly bracket here now and yes I do so I'm gonna get rid of that extra curly bracket right there and save that all of the HTML is largely going to be the same so I'm gonna go over to update student and I'm literally just gonna copy all of the HTML because it also has the delete student part here at the end so this is all the stuff from the last guy and then we can just come in here and select all of this and get rid of it and replace it I guess I should say save it if we have any errors so here's update student let's go and reload that let's just cancel that student ID and let's say we want to delete 16 - lead student and we deleted them all right so there we go we're able to update and delete and insert and do all of that and now I want to show you an example of how we can use cookies now cookies I'm sure you're aware I created a new file called cookie underscore test dot PHP and I loaded it over here and why inside the browser cookies are gonna be used to store values in the user's browser now it's important to understand that you and I'm probably sure you understand this but I'll say it anyway you can't expect that users will have cookies enabled but they sometimes are useful and I'm gonna show you exactly how we can use them so what we're gonna do first is say PHP and to create a cookie you're gonna say set cookie and you're going to provide it with a name I'm just gonna call this my cookie and then I'm gonna put nothing inside of there then I'm gonna put whatever data I want to store so I'm just gonna say sample value then you're going to put time inside of here and I'm gonna say plus 86400 that's the number of seconds in a day and if I want to allow any page from my site to be able to access it I just put a forward slash inside of quotes and there we go we just created a cookie and that's basically simple I mean that's how they work to delete the cookie what you would do is you would come in and do something like use the same exact cookie except you would say that the expiration date would be less than a day so you basically just roll it back to a time that is earlier than what you originally set it for expiration and it deletes the cookie so pretty simple now what we're going to be able to do is let's go and open up some PHP in line here and if you want to check if a cookie is set you can go if not is set and your cookies are going to be stored in a cookie array and we can look for my cookie obviously if you give it a name that's you know kind of unique so you can locate it and then what you're gonna do is in this situation we're gonna say the cookie is not set because we were unable to locate our cookie and else if that goes back as as false or true depending upon how you look at it well in that situation we know that our cookie is set and let's come in and let's say cookie value and let's output that cookie value on the screen let's go like this and get our cookie value how you get the value underscore you just access the cookie array again and say my cookie dot and go and I'll put that on the screen so let's go over here reload it cookie not set its reloaded again cookie is set and it has the value of sample value and that's about how complicated cookies are so there is a cookie example and now what I'm gonna do is show you how object oriented programming works in PHP alright so we're gonna go into htdocs creating a new file and I'm just gonna call this oo P PHP dot PHP that's perfectly fine go and throw in our HTML and close off our body tag and close off our HTML tag alright and I'm gonna create some objects now object or in a programming like every other language is going to just allow us to model real world objects and inside of code and like every objects has attributes such as height and weights and such and everything also has capabilities such as being able to run and eat well with object-oriented programming we model these things attributes are going to be called feet are actually they're going to be called fields and capabilities are going to be called methods or functions all right and this is the same a field is the same as a variable it's just related objects and methods are just like functions so let's go and create one I'm just going to create a simple animal object so how you do that is you use a class which is the blueprint for what you're trying to model and then we're going to define some attributes so I'm going to mark this name for our animal as protected and what that means is there's all kinds of different ways you can say that this is private and if you mark it as private that means that only functions or methods inside of your class are going to be able to access this data now as you're gonna see later we're actually going to be able to create new classes and inherit things like name inside of it automatically but if you do that you're not and you have this marked as private you're not going to be able to inherit the name so I want to be able to inherit the name so I'm gonna mark this as protected and you could also have it marked as public and anything that is marked as public is going to be available this data this value for name is going to be available to anybody who has access to objects created of type animal don't worry I'll give you a lot of examples here and all of this will make sense so we're gonna have a name for our animal we are also going to have a favorite food for our animals what else we will also have a sound that our animal is going to make and we will also have an identification number for all of our animals and a static attribute is going to be shared by every single object so every single time anybody accesses this static value it is going to be the same for every animal object ever created and whenever any of the animal objects change this value it is going to change for every animal object so it's a shared value that's available to every animal object any constants that you define inside of your class are going to also be shared by every single object and you can define functions or methods inside of your class in exactly the same way as you do outside so let's say we wanted to do something like get name and we wanted to provide that name well we would just say return and then you would say this and that just means that's a reference to the object because we create the object after we create the animal class so inside of the class we don't know what the object's name is so if we want to refer to the object itself we use this and I'm gonna say name and that's going to return whatever the animal's name is you're also going to have functions called constructors that are going to be set up to initialize or set values for all of your animal objects that are created and this is what they look like function construct and let's say that we'd like to go and generate a random value and assign to ID we could just go brand and let's say we want it to be between 100 and 1 million have to be a pretty big animal shelter to have any issues with that we could then come in here and say echo this get the ID and then say something like has been assigned a break statement inside of there and you're going to be able to access a static attributes like number of animals by just going animal and then : : and what we want to do is get our number of animals and increment it because we just created a new animal type a destructor is going to be called whenever all references to our objects have been unset so we can go and do things just dropped and we could just output some information like this and whatever the animal's name is is being destroyed so there's another message that we can have you're also going to be able to use what are called magic setters and getters and these are going to be called whenever you try to assign a value to an attribute so we could say function and get and what we're going to specifically assign here is the name for our animal and we can output a message on the screen ask for and name just so we can have some output popping up here and then what this is going to do is return the animals name if you would like to go and check that a value trying to be assigned to your attributes is valid you could do that inside of a setter function let's create a setter function set and this is going to be receiving name as well as value and then what we can do is we could say switch and name and this is going to allow us to set things like or name our favorite food or the sound for our animal types so we could say case name and then this name is equal to how are you and throw a break in there after that and let's tab these in so it looks a little neater and let's copy this a couple times and did I forget to put PHP around yes I did so let's come in here like this PHP and let's close off and let's get rid of that come down here close off that tag and then if this is favorite food that we are favorite food then we will sign favorite food so whatever value was passed inside of here and if we received sound whoops get rid of these dollar signs and sada there yeah and there and change this to sound and change this to sound and then we could throw a default inside of here that just says default and echo out onto the screen in this situation that we were unable to find whatever they were trying to print out to on the screen so not found like that and otherwise outside of the case statement we could come in here and say echo set name to and whatever our value was that they were trying to use with a break statement alright so there we go I'm gonna create another function and it's going to be called run and I'm just gonna say echo this and get the name for our animal and I'll say runs like that go create a couple more this function I'm actually going to override and I'm going to show you how to create a function here that cannot be overridden if you do not want a function to be overridden in a class that inherits from animal just put final in front of it and what is good it's the name of that function and I could say something like echo running is good just to do something silly another thing we can do is we can use a function that is called and there's two underlines there to string and we can use it to define what prints whenever the object is called to print so what I'm gonna say I'm gonna print out a little message or story about my animal I'm gonna say that I want the name and we can say says and then go and get whatever the sound is for our animal and then we can say give me some and then after that go and get the animals favorite food favorite food and then we can have the animals say my ID is and I'll put that on the screen as well by once again going this ID and total animals also is equal to and we can print out our animal number and we'll just say number of animals and anything else no I can't think I know so I'll throw some brake statements inside of there and there we go and you can also define inside of here static methods so static function let's just have the animal be a animal that can count numbers and so we'll say or add numbers so it's gonna get two numbers and then it's just going to return those numbers added together num1 plus num2 and now let's test out our animal so we have our opening curly brace which is for this guy right here and directly outside of here let's just go and close that if I want to create a new animal object I can say let's say I want to have this be animal one I just say new and whatever the class name is so animal there we are just created one and now I can say animal one and if I want to assign the name to it I just say spot and again animal 1 if I want to assign a favorite food just do this and say spot likes to eat meat and animal 1 and define spots sound to be equal to ruff and whenever we actually call these actually what is being called is the setter this guy up here so this is the function being called in that situation now what I'll do is say echo and animal 1 and to get its name I just do that and I could say something like why don't we just go and copy this up here so it's exactly the same as this so I'm going to say that I want to copy this whole entire thing it's not exactly the same so we'll go eka or and yeah echo and instead of putting this inside of here I will instead say animal 1 and I'm going to do the same thing here and I'm a 1 and here and animal 1 and total number of animals this is going to stay as animal because that's a class field or variable whatever we want to call it and if you want to be able to access the constant that we threw inside of there I can say something like favorite number and then just refer to it with its class name so animal and pie and break and there we go now let's get OPP HP dot PHP oops got an error here figure out what we did we have an extra quote inside there get rid of that and we got another little bug oh and it's the same thing because I copied that reload it you can see here a value has been assigned and we got another little bug let's go and figure that out and I forgot to call this number of animals there we go alright so reload it and there we can see we set the name to spot we set the favorite food to meet ruff asked for named Astra sound ask her favorite food ask for ID and then we printed out spots as ruff give me some meat my ID is this number total number of animals is 1 favorite number is this and spot is being destroyed poor spot alright so now we're gonna take all of that that class and we're gonna create a new class called dog and it's gonna inherit all the methods and all the variables and fields inside of the animal class so to inherit I'm right after the animal class I'm gonna create a new class and it's gonna be called dog and to inherit from animal you just say extends animal that's it that's all you do now what we can do is let's say we wanted to come in here and change this run function we can override it inside of here and everything else will still work so throw that in there and we can just say runs like crazy just to change it a little bit everything else is basically the same and even though this is now a dog what we're gonna do is we're gonna copy all of this stuff that we had right here except we're gonna do it for our dog class so there is animal here is dog so I'm gonna call this animal 2 and it's going to be new dog and this is going to be 2 also and we're gonna give it a name of growver and animal 2 and just change all of these ones into twos and let's say that Grover's favorite food is mushrooms and he says ger instead of ruff and this will be animal 2 in this situation says and it will just have to change all these animal 2 and animal 2 and animal 2 total number of animals we're going to set this to dog instead of animal might be surprised by the results there well it's just dog with lower case and we'll get rid of the favorite number it doesn't matter anymore run that and you're going to see all this stuff is the same except now we create a Grover everything continues to work exactly as before and you can see that Grover's being destroyed and spot is being destroyed here at the end and also that the number of animals comes back as two and even though we go and created a brand new class we are still every single time that's still going to be considered an animal even though it's a dog and that's the reason why we get that additional information another thing is remember we overrode the run function well we can come in here and we can say animal one and let's say that we want to call our run function on animal one and we want to do the same thing on animal too right like that whenever we run those you're going to say that the first one runs right here spot runs however Grover runs like crazy all right so you can see we were able to override that and just remember that if I've method is marked as final it cannot be overridden also additional information if we want to go and just see what happens if we try to print out the animal like this animal one and animal - let's just go and copy that and change it to 2 and this is 2 and we run it that it's just gonna automatically print out whatever we put in that to string method we had ok so cool stuff now PHP like many other languages are not going to allow you to inherit from multiple different classes so if you want to get a similar result what you're gonna have to use is an interface instead and how you create an interface you just type in interface and let's say that we want to give our animals and dogs the ability of sync what we would define here is the functions that must be implemented by any class that inherits from this interface so what we're going to say is if you're going to inherit from singable that what you need to do is implement a function called sing inside of your class and let's go and implement that so if you want dog to implement that interface you say implements singable and that means that you must now create a function called sing so I'm gonna go and create a public function public function and it's gonna be called saying it's like creating a contract in there or there's a lot I could make another bad enough extra hour or two to talk about PHP I have other tutorials that cover interfaces and so forth I'm gonna pass on that for this tutorial unless you guys really want me to do it then leave a comment and say talk about all this in another video so I'm just gonna say the dot whatever this dog's name is is going to sing and then I'll say Bow Wow Wow okay so there that is then I need to if I also want the animals to do the same thing again just go implements singable and and why didn't I I label that as an uppercase letter I should have yes it's there all right so back up here implements singable is there singable and like I said before you need to implement that and we really want to do it let's just do it here at the very bottom so here it is saying and we'll just have him say girl girl girl alright and there that is and that is how we can enforce contracts in which our classes implement certain certain functions and then we can come down inside of here and with we wanted to output that information we could just go and let's get rid of this get rid of these two let's get rid of all of these actually it's not get rid of that one just get rid of this and if we want to call the sing function we could just go sing and do it for both of these guys and there we go Grover sings by well and all their spots sings gegege all right another thing that you'd be able to do is let's say we created a function we could actually create a function and this gets a little bit into why interfaces are really cool I can say make them sing and mark this as singable which is the interface and it can be any singing animal that that implements that interface so animal and it's going to make them sing so we'll just go singing animal and have it sing just by going like this and this gets into some really cool things you can do with PHP another thing that's often brought up is polymorphism and the way that it works is basically what we're saying here is that through polymorphism we want different classes that share a superclass so for example how dog is going to share all the values inside of animal we want them to be able to act as animals however in the situations in which the dog is different so for example where we have them run or whatever we want them to be able to act as their different selves even though they are animals let's you know let's bring up make them sing again so we'll just bring that there and let's do that with our different animal types so I'm going to go and call make them sing and pass in animal whoops yeah animal one and also make them sing again make them sing and animal two so here's another example of how we can pass in different classes and also have them both work alright so neat stuff and I guess just about the only thing I didn't do is called the static function that I have inside of my animal class which is somewhere here where did I put it yeah add these so I'll show you how to call static functions inside of a class so we'll say echo and three plus five is equal to and then outside of that you just call animal whichever the class name is we call add these and we pass in the values as 3 & 5 close that off and reload it and you can see that it was able to make that calculation oh and one more thing and this will end the whole entire tutorial that's absolutely huge if you want to go in and check if a different if a object is of a certain type so I could say is it an animal how you would do that is let's try animal 2 so I'm going to say animal 2 instance of animal and I'll use a ternary operator here and I will say true and or false and this and that and then echo out whether it was indeed true or false and that will end the entire tutorial hopefully you guys found it useful and you can see here it comes back as true alright so there you go guys that is an insane amount of information about both PHP as well as MySQL if you actually stayed here and watch the whole video thank you for that please tell me in a comment I would greatly appreciate it and like always please leave your questions and comments below otherwise until next time
Info
Channel: Derek Banas
Views: 125,084
Rating: undefined out of 5
Keywords:
Id: NihZYkNpslE
Channel Id: undefined
Length: 137min 5sec (8225 seconds)
Published: Sun Dec 08 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.