How to upload image into database using PHP and mySQL database.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys in this video we are going to see how to upload images inside the database and how to display images from the database okay now we are going to see this example now here i am having this demo project inside this i'm having one heading and for this i have used bootstrap so that we don't waste our time in styling and also i'll be telling you how to use functions in php okay when it comes to functions we are always trying to keep our code dry that is don't repeat yourself okay we will not repeat the entire code using functions we are going to display the data okay let's see how to use that one before that i'll just show this demo now here i'm having username mobile and choose file now let me just show this demo project here i'll be writing here username rita mobile i'll just write this one choose file and from here i'm just going to select one image okay from here let me just select one image i'll be selecting this image i'll click on this now you can see this image name has come here okay home foot dot jpg i'll click on submit once i click on submit you can see this table this entire image the user name is being displayed here mobile number i am not displaying here only user name and image i am displaying okay if you want you can display mobile as well but you can see this entire data i'm getting directly from the database okay first i'll be storing inside the database and from that database i'm just displaying inside this website now if i just show you the database here i'll just write here localhost and here i'll be writing phpmyadmin okay stylings you can say stylings i have not focused much because i have used bootstrap okay if you want you can give better stylings using css now here this is now php my admin dashboard is open now here i have just created image upload database inside this i'm having this table okay registration table and inside this registration table if i just open this one you can see all the data whatever i have entered that has been stored here okay you can see images hash okay this folder we are going to create and inside this folder we are going to store these images okay you don't have to worry if you don't understand i'll be explaining you step by step i'm not going to skip any part so that you can understand easily okay now we are just going to display this entire data here okay whatever i am having inside the database that data has been displayed and also you can see here inside this database for reta the id is 6 but here inside whenever i am displaying the id number is 5 because inside this database i have deleted id number 1 ok so here i am having correct id numbers whatever it is been displayed but here i'll be having sequential order okay one two three four now we are going to see everything and also here you can see i'm getting this message data inserted successfully whenever i add new data okay let's get started into this and let's create this project let's create this simple registration form and then i'll be telling you how to use functions and then i will be telling you how to insert the data inside the database and how to display that data inside the website okay so for that first you have to install this zamp okay because we already know php is a server-side scripting language so to run php scripts we should always need one server okay here i have just installed exam and here you have to start apache and mysql apache will be acting as a local server to run our php scripts and mysql is the database itself okay we are working inside mysql database so you have to start this both apache and mysql once you started this one after installing xampp just come to that particular directory where you have installed xampp i have just installed in c directory and here i'm having zam i'll just click on this inside this you will be having this htdocs folder just click on this htdocs folder okay first time if you have installed then you will not be having any files here any folders and any files okay i have created projects so here i am having these folders you will not be having these folders now here inside this just create one folder i have created one folder image upload inside this you can see it is empty i have not created any file yet now just right click on this and open with code okay once you open this with vs code editor it is going to open and here we are going to create all the files we are going to create database we are connecting to database we are going to see how to use functions and we will see how to upload images okay now here inside this first i'm just going to create one file i'll be creating index.php now inside this file i'll just come here i'll be searching for getbootstrap.com i'll just search for getbootstrap.com and from here i'm just going to copy css cdn link i'll just click on get started and here you can see here i'm having the css cdn link i'm just going to copy this one first i'm just going to write here basic boilerplate and below this i'm just going to paste that css link and from here till here i'm just going to remove okay if you want you can keep but i'm just removing that one and here i'll just write the heading i'll just write here image upload i'll save this now i'll just copy this entire path and here i'm just going to paste that one only paste and from here till htdocs i'm just going to remove i'll just write here localhost i'll enter now you can see my title has been changed to image upload now if i just write one h1 i'll just write the registration form registration form enter i'll refresh this now you can see here i'm having this output now for this i'm just going to give one class okay i'll be using bootstrap so i'll be using bootstrap classes here now for this h1 i'm just going to give bootstrap class i'll just come inside this one and here i'll be writing class and for this i'll just write here text center okay stylings if you know stylings you can just ignore the styling part and directly you can jump to php code and now for this i just want some margin from top and bottom so here i'm just giving margin y of 3 y is top and bottom okay y axis m stands for margin now here this is my output now below this i'll just come here now below this here i'm having this input fields okay so for that i'm just going to wrap this inside one diff container i'll just come here now below this i'm just going to create one div and for this div i'll just give the bootstrap class container okay container will take only the maximum width inside this diff container i'm just going to create form action i will give later now inside this form i'm just going to create one div and for this div i'll just give the class name as form group okay this is bootstrap class you don't have to worry if you don't know okay once you go to bootstrap and you search for form you will be getting this entire data now here i'm just going to write input field text name and id as of now i'm just going to remove okay name i'm not going to remove only id i'll be removing and here i'll just write username i'll save this i'll come here i'll refresh this one here i'm having this input field now for this i'm just going to give one placeholder i'll be writing placeholder placeholder is username okay something okay you can give anything here i'm just going to write here username save okay now you can see here i am having this placeholder now this form i want completely in the middle okay so for that first i want it to take complete hundred percent so we are adding one class here for this input field and here i'm just adding here form control now once i add this bootstrap class it is going to take complete hundred percent of that diff container i'll refresh this it is taking complete hundred percent of that diff container which we are creating here okay which we have created here this one now i want i want this form to take on the particular width so for this entire form i'm just going to give the class and class i'll just give here width to be 50 percentage i'll save this i'll refresh this one now you can see it is taking only 50 percentage because it has reduced in size and you can see it has reduced in size and here i'm having this output if i don't give this 50 percentage i'll save this i'll refresh this one you can see it is taking complete hundred percentage i'll just do ctrl z now now if i just show you the output it will be taking complete 50 percentage now i want this form in the middle so for that inside this diff container i'll be using display to be flex and also we are having once we use display flex we can use justify content i'll be writing here justify content justify content to be center i'll save this i'll refresh this one now you can see my form has come in the middle now if i just show the demo project here i'm having username mobile and choose file now again i have to copy this entire thing and here i'm going to paste that one again in place of text in place of name i'll be writing here mobile and here placeholder i'll be writing here mobile and finally here i'm having the same thing i'll save this one i'll refresh this okay now here i'm having this output now for this i'm just going to give some margin now for this input fields now for this diff container i'm just going to add some margin top and bottom and here also i'll be adding margin top and bottom i'll save this i'll refresh this one now you can see here i'm having this forms but here if you see here this both the things i am repeating okay this both the things i am repeating so i don't want to do that one so now here we are using the concept of functions so for that i'm just going to create one file i'll be writing operations or you can give any file name i'll just write here operations.php now inside this file first i'll be writing this php syntax i'll just close this left panel now inside this i'm just going to create one function i'll just write here function and i'll give my function name as input fields inside this function i'll be passing parameters first let me add here placeholder okay placeholder we are having separate for each one username mobile password so placeholder i want next i want to add name next i want to add value and finally i just want to add the type okay type it is text or it is email or it is file okay i just want to add that one i'm just passing four parameters inside this function now inside this i'm just going to create one variable let me just write this variable name as element and here i'll just open this double quotes and here i'll be closing this one now inside this double quotes i'll just come to index.php this entire div i'm just going to copy and here i'm just going to paste that one now for this you can see here also i'm using double quotes sorry and here also i'm using double quotes so to avoid this here i can just use this black slash and here also i'll be using this backslash okay either you can concatenate or you can use like this okay either way you can do next i'm just going to do instead of type i'll just remove this type from here instead of this i'll be using this type okay whatever i have passed here that i will be using i'll copy this one i'll just close in single quotes and here i'm just going to paste that one instead of this username i'm going to remove this and here i'm just going to paste this one i'll just wrap in single quotes and here i'm just going to paste and placeholder also i'm just going to remove single quotes and this one i'm just going to paste i'll copy this and here i'm going to paste and finally for this also i'm just writing here backslash okay escape characters not here i'll just write this one here finally we want one more attribute that is value and inside this i'm just going to write this value okay whatever i have passed here i just want to store that one here this is how we are going to create functions okay now this entire thing whatever we are passing here that we can use repeatedly okay now inside this index.php i want to use that function so for that first i just have to include that one okay i need only one time i just need only one time so i'll be requiring that one instead of including i'll just write here require once okay i just want to require once and inside this i'll be writing that file name i'll just write here operation dot php okay let me just check for the file name operations it is operations i'll be writing here operations.php okay i'm just requiring once require once means only one time i required this one but again if i just load that one it should be there okay so for that i'm just going to use that one now i'll just comment this entire thing later on i'm just going to remove now instead of that instead of writing this i will be opening this php syntax and here i'll be closing that one inside this php i'll be writing this function name input fields and here i'm just going to paste that one okay before that if i just comment this one and if i show you the output i'll refresh this you can see both the fields will go because here i have commented that one now inside this function i have to pass four parameters i'll just open this one now first i'm having placeholder so placeholder i'll just write here username next i'm having name okay next i'm having name so for name i'll be writing here username okay this name is very important and here i'll be writing username and next i'm having value value i don't want so i'm just giving here empty next finally i'm having type for type i'm just going to give a text i'll just write here text i'll save this okay now let me just remove this comments from here i'll save this one i'll refresh this when i refresh this one here i'm not getting this output because inside this function i don't have anything to print like okay i have just passed this one now to get that one i just have to print that okay to print variables inside php we are having this echo echo function and now here i just want to print this one now this element is having this entire thing so i'm just printing that one now if i just refresh this now you can see here here i'm having this input field let me just change this one to username i'll save this i'll refresh this one now here i'm having this output okay now we are having this one and also inside this here i'm going to add one more attribute that is nothing but auto complete now here i'll be writing this one auto complete auto complete to be off and here i'll be writing this i'll save this one because whenever i click i don't want the suggestions to appear now whenever i click i will not be having any suggestions now in the same way now i don't have to repeat this entire thing i just have to write this function i'll just write here three times and instead of this i'll be writing here mobile and here i'll just change it to mobile and finally type let it be text placeholder i'm just going to remove we don't need any placeholder when we are uploading images now next name i'm just going to give here file value i don't need and type also i'm just going to give here file okay for images you should always give the type as file okay only then you will be getting this option okay choose file now if i just refresh this one you can see here i'm having username mobile and this choose file okay this entire thing okay we are just creating using this function okay this is how we are going to use functions in php now i am just going to remove this entire thing instead of that we are just creating one function we are just using this php syntax we are calling this function three times and we are just passing this different arguments below this i'm just going to create one button and for this button i'm just going to give this class btn btn dark inside this let me just write here submit i'll save this i'll refresh this one now here i'm having this button now for this i'm just going to add type for this button i'll be adding type type is equal to button okay if you want you can use input field and you can pass the same arguments here or else you can create separate function for buttons if you are having multiple buttons and you can use the same okay you can create the same function okay you can create different function you can give different function name and you can give that for buttons as well now for this button i'm just going to give this name attribute name attribute is very important when it comes to php now for this name attribute i'm just going to give here submit okay now we are done with this basic styling i'll just come here i'll refresh this one now we are done with this basic styling here i am having username mobile choose file now when i click on choose file this popup will be open and from here i can choose the images now here if i just select this one you can see here i'll be having this image name now whenever i click on submit i just want to display that data inside another file okay before that we just have to create the database so come inside this phpmyadmin dashboard just write localhost phpmyadmin now here i'm just click on this new and here just give the database name i'll just write here image upload project click on create now this database will be created you can see here i'm having this image upload project this one now inside this database i'm just going to create the table let me just create registration itself now for this i'm just going to give the fields for id i want for user name for mobile and for image so totally four fields so here i'm having four i'll just click on go inside this image upload project i'm creating table that is registration inside this first i'm just going to give id second i'll be writing here name third i'll be writing mobile and finally image okay these four fields i'm just writing for int for id the data type will be in for name i'm just going to give here var car and size i'll just give here 100 for mobile also i'm just going to give worker and size i'll just give 20 for image also i'm just going to give worker and size i'll just give here 200 okay this is the simple fields i'm just creating now just scroll this one now here you will be having this ai comments just enter this one this is nothing but auto increment which means each time you don't have to enter the id number it will automatically generate one number to you and by default it is going to start from one and it will increment by one once you give this auto implement this id field will become primary which means that it uniquely identifies each record in a table so it is primary and here i have just given this auto increment okay once you create this one just click on save okay now we have created the database image upload project inside this we are having this table registration inside this registration i am having all these fields id field name field mobile field and image for id i have given auto increment and primary okay for name for mobile for image i have not given anything i have just given the data type and size okay now once we are done with this now we have to connect to this database only then we can insert the data only then we can display the data so to connect to database now here i'm just going to create one file i'll be writing connect dot php now inside this file first i'll be writing this php syntax now here i'm just going to create one variable i'll just write here con and inside this i'll be writing this one mysql like connect and here inside this i'm just going to pass four arguments first i'll be passing my server name that is nothing but localhost next i just have to pass the username my username is root next password i'm just going to pass if you have installed xampp and if you have not changed your password inside localhost phpmyadmin dashboard then your password will be empty but i have changed my password so i'm just giving here my password and next finally we have to pass a database name okay in which database we are working now i have just created image upload project so i'll be writing that one i'll just write here image upload project okay this is the database i have created now here i'm just going to write one condition if my connection is successful then i just want to print that this one i'll just write here connection successful else i'll just close this using semicolon else if i have any error then using this die function i just want to display that error i will be writing here mysql i error and inside this we just have to pass this connection variable if you are having any error inside this connection variable then display me the error always display me this connection successful message i'll copy this path and here i'm just going to paste that path and from here i'm just going to remove i'll just write here local host enter now you can see i'm having this connection successful which means that i am successfully connected to my database now i can insert the data inside the database and also display the data from the database now once we are done with this close this one and also i don't need this file i'll be closing this now inside this form for action i'm just going to create one file display dot php i'll just write here display dot php whenever i click on submit button my action whatever code i am writing i will be writing inside this display dot php file and from there all the code will be taken and whatever i write that will be generated and that will be displayed now here i'm having display.php and i'm just going to write this method method is equal to post okay using post method i'm just going to perform all the actions so whenever i click on this submit button okay instead of button i'll just write his submit type is equal to submit whenever i click on this button i will be redirected to display.php file i'll save this i do control b and here i'm just going to create that file display dot php now inside this file first i'll be writing this basic boilerplate and here i'll just write this one display data and below this i'm just going to link this css file i'll just come here i'll copy this bootstrap css link and here i'm going to paste that one i'll save this i'll come here i'll come to this one i'll refresh this now before that let me just write one h1 here h1 i'll just write a displaying data i save this i'll refresh this one now when i click on submit you can see i'm redirected to display.php file and now here i'm having displaying data as my output i'll just remove this one now inside this file we are going to write the entire code now in this file we are going to display the data now to display the data first we have to insert the data inside the database so for that we are going to write the code now now here below this doctype i'll just write this php syntax okay now i am inserting the data inside the database so first i have to connect to the database and to connect to the database i have already created that one okay this particular file inside this i am connecting to the database now inside this display.php file i am just including that file i'll just write this one include and inside this parenthesis i'll be writing that file name i'll just write here connect dot php file save this i'll come here i'll just refresh this one now you can see here i'm having this connection successful inside display.php file which means that i am successfully connected to the database but i don't want this message to be displayed each time when i load this page so for that inside connect.php i'm just changing the condition here if i am not connected successfully then show me this error this particular error i'll just remove this else part and also i'm just going to remove this echo i'll save this only if i am not connected to the database show me this error or else don't print anything now if i just come here i'll refresh this one now you can see i don't have anything which means that i don't have any error and i am successfully connected to the database because inside this display.php i have just included this file now below this i'm just going to write this one if is set okay whenever i click on the submit button i want only then my data whatever code i am writing only then it should work so here i'll be writing this post okay super global variable inside this i'll be writing this submit okay this submit i'll just tell you what is this now this submit whatever i have written here that should be matching with this particular name okay whatever name you have given here that should be matching this one okay name attribute is very very important in php now this should be matching with this one okay you can give any name here but here i have just given submit i'm just telling whenever i click on submit button only then i should perform all these functions now whenever i click on submit button i should extract all this data i'll just come to demo project now here inside this i'll be writing some value here if i just write here kahanam okay here i'm just writing khanam here i'll be writing some mobile number and here i'm just selecting one image i'll just select this one okay let me just select this food five let me just select this image open now here i'm having this image for dot jpeg now this entire values i have to access i'm just storing after accessing i'll be storing inside one variable and that variable i'm inserting inside the database okay this entire thing i'm just going to access now now for that to access that now here i'm just going to create one variable okay variable name you can give anything using post method okay we are using post method inside this for username whatever name we have passed here okay for username this is our name okay this is our second parameter that is name if i just come to operations.php you can see this is our name okay the second parameter so here this will be our name username i'm just going to paste that one okay i'm just accessing username i'm storing inside this variable that is nothing but i am just accessing this khanam and this kanam value will be stored inside this variable now next i'm just going to create mobile variable i'm going to do the same thing i'll just write this post method and here inside this whatever name i have passed for mobile this one i'm just going to copy this and here i'll be pasting that one okay now to access images we are having dollar files okay we are having files global variable now here i'm just going to create one variable and to access that one i'll be writing this files okay you just have to write this files global variable inside this whatever name you have passed for file i have passed this file i'm just going to copy the same thing and here i'm going to paste that one okay i'm just copying all the things i'm copying all the values i'm just accessing all the values i'm storing inside the separate variables okay now this let me just print this one now if i just print and here i'll be writing this user name i'll just write this echo and here i'll be writing one break tag okay so that the output will be printed next line again i just want to print the mobile so i'll be writing here mobile and also i'm just going to copy the same thing and here i'll be pasting that one i'll save this i'll just refresh this one now here i'm just going to write one user name and here i'll be writing mobile i'll just select one file this it is not going to be printed i'll just open this one i'll just click on submit now here you can see username is printed and mobile is printed but here i'm having this notice undefined indexed file okay here for this i'm getting this error okay now again if i just print that one again i'll be getting the same error because this file okay this is nothing but it is two dimensional associative global array so it is returning array and while we are submitting the form we have to submit one multiple data okay because we are submitting array array is nothing but it is going to store multiple values now to store multiple values to store multiple data or to submit multiple data we just have to write one attribute inside index.php file now here inside this form here i'm just going to write this one i'll be writing this ink type is equal to you just have to write like this multi-part slash and here inside this you have to write form data okay we are submitting form data you just have to write this attribute n type is equal to this particular data once you write this then you will not be having any error i'll just come here okay i'll just refresh this one now i'll be writing some name mobile choose any file once you write that one then you will not be having any error okay here i am having the sima and mobile now if i just want to display the image i'll just come to display.php now if i just want to display i'll be writing this echo and here i'll be writing this image i'll save this i'll just come back i'll just select any of the image and here i'll be writing some name let me just write here reema and here mobile some number submit now you can see i'll be getting this array to string conversion okay now i already told you this is nothing but it is two dimensional array so for that we are going to use instead of echo we will be writing here print r now when we are writing print r we have to write like this in parenthesis it will help us to print the array data i'll save this i'll come back i'll just write one name let me just write here sima i'll be writing one mobile number i'll be selecting one image open now when i click on submit you can see here i am having this array and here i am having this name filled inside this i am having this name of the image again here i am having this type and type is nothing but image this one again i am having the stamp folder my image is saved inside this particular folder and here i'm having error 0 which means that i don't have any error and finally i'm having this size okay to print array data you should always use this print r and inside parentheses i'm just passing this data okay now i just want to access this particular name i just want to access this name i just want to access this type and i just want to access this temp name okay we will see how to use that one and also i'll be accessing the error now this is nothing but array okay array can be accessed using index numbers so we will see how to do that one now first i just want to access this particular name okay whatever name i'm having here this particular name i just want to access so here here i'm having this name attribute okay here i'm having this name index so for that here i'll be creating one variable i'll just give my variable name as image file name okay you can give any variable names and inside this okay this is nothing but array i'll just copy this one and here i'm going to paste and from here i just want to access this name attribute okay name field i'll save this okay this particular thing i'm accessing so i'm just writing that one here let me just write here print r and inside this i'm just going to write this variable name image file name i'll save this i'll refresh this one okay now you can see here i'm having this bike for okay this entire bike for jpeg that has been printed here okay if i just right here break i'll just copy this one and here i'm going to paste and also here i'll be pasting that one okay only name i'm accessing so you can see here i'll be getting this particular name okay only this name i have accessed and i am just printing that one now next i just want to access this error this particular error i just want to access so for that okay if you don't access then also it's fine now here i'm just going to write here image error okay let me just write here image file error inside this i'll be writing this image variable and here inside this i'm just going to pass this error now here i just want to print that one to print i'll be writing here print r and inside this i'm just going to pass this image file error i'll save this i'll come here i'll refresh this one now you can see file error is zero so here also i'm having zero and here zero has been printed okay i'm accessing separate values and this values i'm just going to store inside the database after combining everything i'll be storing inside the database now next i just want to access this temporary name okay this entire thing i just want to access now below this first i'll be writing this break okay so that my output will come in next line and here i'm just going to access that one now here i'll be writing this let me just write here image file temp image file temp inside this i'll be writing this image variable and here i just want to access this temp name i will just do here print r inside this i'm just going to pass this one image file temp i'll save this now you can see here whatever i'm having here temp name i have just passed i'll refresh this one okay now entire thing has gone i'll just come back i'll just select one particular file particular image and here let me just select this one i'll submit now you can see here i'm having this temp okay whatever type i am having here this particular directory i am getting as my output okay this is my name this is the error and this is the temp file name okay now from this image now you can see this is my image name this is the error and this is the temp folder temp directory now from this particular name i just want to separate this particular this name okay this name and this extension suppose maybe i'm having png suppose if i'm having jpeg so i'm just separating this and this so for that we are having one function now here i'll be writing this one i'll just copy this and here i'll be writing that now below this now below this i'll just i'll just create one variable i'll be writing here file name and let me just write here file name separate i'm just going to separate file name and the extension separate is equal to we are having this explode function explode method or function and inside this i just want to separate wherever i'm getting dot i want to separate from there i'll just separate using comma and next i'm just going to pass this extension okay this entire file name i just want to separate from this file name okay i got bike dot jpeg from that file name i just want to separate wherever i'm getting dot i just want to separate that one now once i have separated that suppose here you can see i'll just show you now here i'm having by by three dot jpg first i'm just separating this one this is the first part and this will be the second part okay after dot it is going to separate so we are going to use this explode method i'm just writing here dot wherever i'm having dot just separate that one now below this i'm just going to write this one let me just write here print r and inside this i will be writing this name file name separate i'll save this i'll refresh this one okay again it is gone i'll be selecting one image i'll just select one image okay let me just select this home foot open submit now you can see here inside array zero home food is stored inside array one this has been stored okay extension has been stored okay this has been separated and this has been separated and it is stored inside one array and here i'm having this output inside zeroth index i'm having home foot inside array index one i'm having this extension now once we get this one i'm just accessing this last part array index one okay you can access in two ways i have two ways to access the last part you can use any one of them so first i'll be writing the first method now below this i'm just going to create one variable i'll just write here file extension i'll just write the proper spelling file extension now inside this i'm just going first i just want to convert into string lower if it is in capital letters it will just convert into lower letter and here i'll just write this one i'll be writing this file name i'll just copy this file name separate this is nothing but array and here i'm going to paste and here i just want to access array index one now i'm just going to print that one i'll be writing this print r and inside this let me just write this one file extension i'll save this let me just copy this and here i'll be pasting that one i'll refresh this okay again i have to select one image i'll just select the image i will just select this image 12 open submit ok here i am having this undefined function string lower it is string two lower i'll save this i'll refresh this one now you can see here this extension has been separated okay this entire thing has been printed you can access either like this using array index or i'll just comment this one i'll just come down or you can access like this i'll just copy the same thing and here i'm going to paste and instead of this here i'm just going to write this end method and here i'll just wrap inside this one i'll just remove this i'm just telling that i just want to access the end part i just want to print that one i'll just copy this and here i'm going to paste i'll save this i'll refresh this one now you can see again i'm having the same output okay you can use any one of the method to access the end part now here i let me just keep this one you can either use this one or you can use this one okay don't get confused i'll just explain you this one now this is nothing but it is two dimensional array it is going to return array so to print array we should always use this print r now here inside this we will be having some attributes here we are having name we are having type temp name we are having this error and size now to access individual data types okay i am just creating this one separate variables for each one of them i am accessing name error and temp name from this particular fields itself i am accessing this one i am storing inside separate variable now from the name from image name i'm just separating from dot i'm just separating the image name and the extension okay here i'm just printing that one now to get only the extension you can either use like this or you can use like this you will be getting the extension now here i'm just going to create one variable i'll just write here extensions now inside this i'll be storing array and inside this array first i'll be writing this jpeg okay i'm just writing the extensions i'll be writing jpg and finally i'll be writing png okay you can use many extensions like you are having diff okay you can use as many extensions you want but i'll be using these three extensions jpeg jpg and png now here i'll be writing the condition if and here i'll just write this if in array i'm telling that if inside this array i'll just copy this file extension okay this is going to return me the last extension of the image either let it be this one let it be this one or let it be this one okay like this it is just going to written jpeg now here i'm just checking the condition if inside my array i'll just separate using comma and here i'm just going to pass this one okay whatever extension i got from the image if it is present inside this extension variable that is this out of this three if it is present only then i just want to insert the data inside the database i'll just come down now here i'm just going to create one folder here i'll be writing this upload image upload image inside this here i'm just going to create one folder images inside this i just want to store all the images so i'll be writing this one and here i'll just write this dot and this particular file name this entire file name i just want to store i'll copy this one and here i'm just going to paste that one okay whatever file name i'm just accessing i'm just copying that one i'm storing inside this images folder now once you write this one you just have to create this images folder here i'll be writing here images okay now my images folder is empty i don't have any images inside this now whenever i insert the data inside the database all the images will be stored inside this folder itself so before only you have to create this folder now whenever i'm just telling that whenever my file extension is present inside this array only then you just have to create this folder and you have to insert the data now here i have created one folder now you have to use one method i'll be writing this move uploaded file now this will help us to upload the file inside the folder and it will help us to move that file now here i'll be writing this move uploaded file inside this i just have to move inside this template this one this is the our directory i'll copy this one and here i'll be pasting that one i'll just separate using comma and this particular image i'll just copy this one this particular image folder i'm just moving that one okay we are having this temp folder here suppose we are okay by default we are getting this particular folder where our image will be stored here i am just telling that move uploaded file this uploaded file i just want to move here okay so i'm just writing this one don't get confused if you are not understanding just practice this two to four times then you will understand this one okay here again i'm just creating one folder whatever image i'll be uploading that will be stored inside this folder now here i'm having this image uploaded file method and inside this i'm telling that this particular folder just move this one so here i'll be creating one variable inside this i'll be writing the query i'll just close using semicolon now here i'll be writing that query insert into we just have to write the table name here i'm using this back text okay these are not single quotes i'm using backticks and my table name whatever i have created here registration i'm just going to give that name i'll be writing here registration insert into registration and here inside this i just have to pass the fields i'll be writing name i'll be writing mobile and finally i'm just writing here image okay this whatever fields i'm passing here that should be matching exactly with this one okay name mobile and image i'm not passing this id because i have given here auto increment and also primary name mobile and image this fields i am passing here insert into table name this particular fields and here i will be writing these values and inside these values i just want to pass this values okay first i want to pass this image first i just want to pass this username i'll copy this one and here i'm going to paste that one i'll separate using comma next i just want to insert the mobile number i'll copy this one and here i'm just going to paste that one again finally i just want to upload the image now i just want to upload the image my image is in this folder so i'm just going to paste that one here now once we are done with this we have to execute this query so here i will be creating this result variable inside this i'll be writing this one mysqli query and this is going to take two parameters first is my connection variable and second is my query variable sql and here i'll be writing this one if my result if it is true only then i just want to print this one i'll be writing here data inserted successfully else here i'll be writing this one and here i'm just going to write this one mysqli error if i'm having some error then print me this error and here inside this i'm just going to pass this connection variable now this connection variable is present inside connect.php i'm just passing that one here i'll just come here i'll refresh this one i'll just come back now here i'm just going to write kanam mobile number i'm just going to write some random number i'll just select one file and from here i'm just going to select this file image tools open submit now here i'm having data inserted successfully which means that my data is inserted successfully inside the database now this is my table i'll refresh this one now inside this registration table i'll just come to registration table inside this table you can see whatever name whatever mobile number and images i have inserted that has been uploaded here okay you can see this is my folder images inside this i'm having image2l.jpg okay this is how we are going to insert the data inside the database now whatever data i'm having here that data i just have to display i'll just come back now again i'm just going to insert one more name i'll just write here sigma mobile number four four four four i'll just select one file and from here i'm just going to select this one let me just select this particular thing open submit data inserted successfully i'll come to database i'll refresh this one okay it's taking time to refresh but once it is refreshed you can see this data has been inserted here okay now this entire data i just have to display now in place of this i just want let me just come here now in place of this in place of this i'll just come to bootstrap and here you will be having alerts click on this and from here i'm just going to copy this one okay this success i'll just copy from here i'll copy this and here i'm going to paste that one here i'll just use single quotes and here also i'll be using single quotes i'll just remove this one i'll just write it data inserted successfully and also here i'll be writing strong tag and just write here success i'll save this i'll come to my project i'll come back i'll insert i'll just refresh once i'll insert another data let me just write here reema i'll be inserting five five five five i'll select one file let me just select this home foot open submit submit now you can see here i am having data inserted successfully i'll just give one space here then i'll be having some space here okay now this is how okay this entire thing i'm just going to comment only for explanation i have just printed this one later on i'm just going to remove that now below this i just want one display table okay like this table i just want to create where all the data will be displayed from the database so now inside this body i'll just write h1 here i'm just going to give the bootstrap class i'll just write here text to center and also some margin now inside this i'll be writing this heading i'll just write here user data i'll save this i'll come to my project i'll refresh this one now here i'm having user data now below this below this one i'm just going to create one div and for this div i'll just give the class name as container and also i'm just going to give some margin top okay margin top of 5 now inside this i'm just going to create the table so i'll just come to bootstrap now here i'll be searching for table okay i'll be selecting normal table i'll search for that and from here i'm just going to copy this one okay this entire table i'm just going to copy instead of this let me just copy okay let me just copy the entire table and below this i'm just going to paste that one i'll come here i'll refresh this now you can see this table has been displayed now in place of this this table rows i want to display the table data whatever i'm having inside the database i'll just remove this one two trs now here let me just remove this let me just remove this and here i'll be writing here serial number and here i'll be writing username mobile i don't want to display mobile data let it be inside the database so i'll just remove this one now here i'll be writing here image now for this table i'm just going to give border i'll just write here table bordered here i'm just going to write that one table bordered i'll save this now here you can see i don't have any borders for the table i'll refresh this now for entire table i'm getting this border now for this table i'm just going to give the width which i'll just give 50 percentage i'll refresh this now it is taking only 50 percentage of the width now i want this table in the middle so for that for this diff container i'm going to give display to be flex and also i'll be giving justify content to be center justify content center once i give this one my table will come in the middle i'll just give this i'll refresh this one now you can see my table has come in the middle now for this table header i'm just going to give one class okay you can avoid this stylings if you want i'm just going to give some stylings i'll just write a table dark i'll save this i'll refresh this one okay now here i'm not having that one okay let me just check table dark i'll just copy this one we should give here sorry i just have to paste that one here i'll save this i'll refresh this one now here i'm having this output now here from here i'm just going to remove one data i'll just remove this let me just write here one let me just write here kanam and finally let me just write ah let me just remove this and here i'll just write image i'll refresh this now here i'm having this table now in place of this dummy data i just want to display the data from the database now below this body i'll be writing this php syntax i'll just close this php syntax here now inside this i'll be writing one sql query i'll just write here sql and here i will be writing this select star from registration okay this is my table name registration which means that i am selecting all the data from the table select star from registration now this star means select whatever data i am having inside the database select this entire data now i have to execute this one so i'll be writing this result variable and here i'll be writing this one and here i'm just going to pass this connection variable and query variable now below this let me just write this row and inside this i'll be writing this one mysqli fetch fetch a soak method and inside this i'm just going to pass this result variable now this is going to fetch all the data present inside the database here i'm just selecting all the data and here i'm fetching all the data present inside the database now if i just echo this one i'll just write here echo and here let me just write him name i'll save this i'll come to my project i'll refresh this one now you can see khanam has been displayed here which means that whatever data we are having inside the database the first data whatever i am having inside the name that has been displayed here now if i just want to display image i'll just write here image i'll save this i'll refresh this one now you can see the image path has been displayed here only the first data has been displayed but i want all the data should be displayed so this entire thing this entire thing we just have to wrap inside while loop i'll just write here y this entire condition i'm just going to copy i'll cut from here i'm just going to paste that one here now this while loop is going to run unless and until i have the data inside my database now here i'm just going to access the id i'll just remove this one now here i'm just going to create one variable id and here i'll be writing this one row and from database i'm just going to access the id field okay this id field whatever i am giving here that should be matching with this particular field okay this field okay this id field now below this i just want to access the name i'll just write here name i'll be writing this row variable inside this i'm just going to access the name field next i just want to access the image so i'll be writing here image i'll be writing this row and here i just want to access the image path now i have accessed all the variables all the values from the database i have stored inside this variables now here i'm just going to print i'll just write here echo inside the single quotes this entire table data i just want to print i'll copy cut from here and here i'm going to paste i'll save this i'll come to my project i'll refresh this one now you can see three times my data has been displayed because inside the database three data's are present and hit three times it has been displayed because this while loop is going to run three times unless and until my data is present inside the database that is going to run now in place of this i just want to print this id okay this id i just want to print now here i'll be writing this i'm just going to concatenate with this one okay this particular single quote this single quote again i'm concatenating this id again this particular data and this data next i'm just going to remove this one i'll be writing this one and here i'll just write this name and finally again i'll remove this here i'll be writing this image i'll save this i'll refresh this one now you can see the data whatever i'm having inside the database that has been displayed but here i'm getting this path now instead of this i want image so here i'll just remove this one instead of this i'll be writing this image tag i'll be writing this src now inside this i'll be writing this image i'll just concatenate with this one and here i'm just going to close that one i'll save this i'll refresh this one now you can see entire image whatever i have stored inside the database that is been displayed now here i'm just going to use this style tag i'll just come here now here i'll be writing this style style now inside this i'll just write this image for this image i'm just going to give the width as 200 pixel i'll save this i'll refresh this one now here i'm having this image okay if you want you can just reduce the size i'll just write here 100 pixel i'll refresh this one now you can see entire data whatever i am having inside the database that has been displayed here this is how we are going to insert the images inside the database and display the images from the database now here i'm just going to write one name i'll just write here suresh here let me just write 555 i'll be selecting one file and here let me just select this particular image image 21 i'll open submit now you can see this image has been inserted okay this entire data i'm getting because i have printed that one okay as of now i'm just going to comment this one i'll just come into this i have commented i'll be selecting this image i have sell i have just written rameshan number and this image submit now i am having success data inserted successfully and this data has been displayed here okay this is how we are going to insert the data and we are going to display the data okay if you want you can just refer this one okay i'll just come here okay if you want you can just take the screenshot of this and you can practice this one that's all for today's tutorial thank you so much for listening have a great day
Info
Channel: Step by Step
Views: 75,463
Rating: undefined out of 5
Keywords: php projects, php crud operations, crud php, php top projects, database projects, mysqli projects, php create read update delete, javascript projects, php full course, projects in php, how to perform crud in php, php for beginners, khanam php, backend programming, how to upload images into database, how to display image in website from database, khanam how to upload image in databse, how to create databse, how to connect html form to databse, image upload in database, php, css
Id: iDKl5aoLjUo
Channel Id: undefined
Length: 55min 25sec (3325 seconds)
Published: Sat Nov 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.