php newsletter & mailing system #1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome back to my next tutorial we're going to be creating a newsletter functionality and in this tutorial we'll be doing this in purely php and html cs with some little bootstrap just to make this easy so in today's tutorial we'll be discussing about some really cool stuff about inserting data to database selecting from the data fetching data also from the database and also built in some records from the database so stay tuned now on my left hand side here i have my cool vs code editor and on my right hand side i have my browser open with some blank each index page and i'm i'm going to close this up with some blank index pdf so this is the this way once the user um visits this page we want to dive into the index page and this is where the newsletter is going to show up here so let's start let's move into the code now okay so what i'm going to do now because in my direction here you might just use that directory i've created some folders here when bringing some files in so the first one i need to do is about the the include folder here then for the contains some files which i need to link to externally in my page here like for example then head.php the head.php here will include let me just delete this and show you what what i mean here the psp we include the html head tag which will contain the title of the app of the project here the external links and also submit attacks here and right enough the php will contain as you can see see right now is actually blank then now the php will contain the navigation bar of the index page why they flip the php it doesn't contain the footer tab that is the copyright and stuff like that so let's begin by pressing out some headstacks here so um what you're seeing doing this here i'm i'm i'm going to be using some emmy type abbreviations which makes things easy i'm faster so i'm going to click on shift plus i'm using windows here so everything with windows yeah you have to click on shift plus yeah one here extension mark and once you click on that you're going to see some drop down here as you can see it's it's indicated emit abbreviation so just click on tab and once you once you've done that to bring us some of this html boilerplate here so all you have to do is change the name of the of the of the title of the app here which is what newsletter newsletter uh so the next thing we need to do is to bring in our our external files and some of these s95s are the css right now is it contained both the bootstrap and our stacks our style the css page and also the javascript which contain the bootstrap midfield version and the jquery some main gs value so to do that i'm going to indicate some comments here that i showed this is the css and also the javascript we go here okay let's bring in our system css files so i'm gonna do link column css and click on my tab just to do that then i'm gonna go into my css folder right now it's actually in this status folder then select or boost our stylus style css so all this is saying is that my css folder slash inside it style.css i'm going to copy this one more time place it one more time then change this one to also to bootstrap bootstrap dots mean 5 version you know what javascript folder when using bootstrap your this you resource that was via the first page here and sorry when using any external javascript code called code yet the source which must be with the first here at the heading must be your jquery file you know for the for any bootstrap and and script to work so we're going to say script sorry about that scr all right pt sorry s-e-r-i p-c then coulomb sorry column source then click on tab and we're going to go into the javascript folder i'm going to say js slash i'm going to say jquery dot js i'm going to copy this and paste it one more time and also boots sorry about that bootstrap the js okay so i think this is all we need now this would be inside this part here is going to be inside the head party why is down blue the future it's gonna be inside the pastry so they just make some things clear we're gonna get some tags they like the footage the footage sorry we're gonna give it the class of a pardon pattern of two sorry to name background of dark okay so that was that would just create a simple um dark background and footage here also beginning we're gonna give it a copyright symbol sorry a copyright on the class um i i want to say newsletter sorry casper oh sorry sorry i can't mean that so i'm gonna say and copy okay like that so i'm going to cut this out and paste it inside the h file here paste it inside there then also what we needed in our last include um file is actually another php this is another php we'll be using the bootstrap navigations which will make things more easier for us instead of starting the whole phone number we're going to be doing this simply with the bootstrap so we're going to say now now a class of navbar a class of naf ba dak also a class of knock bar expand um md and also a class of uh bg dark okay this is just this we just give you some some of those classes which are right here is inside that directly inside a class instead of these same actions here so we're gonna move down i'm gonna give it some branding or brand name and for that we're gonna save a span of naba brand so it will be our a-n-d i'm going to give it a name of what's our beta of newsletter okay this this will just create some a little text logo here continuing this text here now the next thing which we need to do now is for me to create the the programming and what i mean by the vocabulary is those three dots which we which you're going to see in some apps or websites now once you click on it either expand or slide it so to do that we also have the class called we're going to be placing this button inside a button so inside this button we'll give it a class of button just okay now this button will also contain some data attributes for example the data id we're going to give it a data id of let's say collapse we'll be using this later on and also the data toggle data sorry guitar toggle sorry about that data toggle we're going to give it data of what other let's say data toggle of [Music] collapse sorry okay let's just look it up i don't know what is what goes in here so i'm going to search for some stuff right now okay considering w3s to stop for that let's move on yeah so you have to be looking up for some stuff you know for you to get knowledge about all this blue strap yeah you can boot shop for because that's what i mean because right right now and by the way this is the but this is actually the the bugamin which i was talking about once you click on it it slides in and it's sliding back okay let's we're looking for everything now and for that class we're going to give it a class um we're looking for that little toggler icon here sorry the button here um know that so as you can see collapse so actually the um id we're going to be placing this in some div tag here okay so we're going to say the data toggle of collapse [Applause] and inside this button we're bring up placement a an icon there and that icon will be in his panty with a class of navba toggler icon i'm still going to say a span of the class of what navda jumbler icon okay and that should do it now the next thing we need to do is that we need to reference this idea in our div and for that we're going to say oh let's just copy some codes here and paste it one more time then i'll explain it to you i'm going to copy down this div here i'm pasting here so we'll just waste time and what this is already doing is that we are is we are giving the class of collapse and in number of collapse now what this would do is that when this stream just like ipad level or pcm level here all these links here we show once the screen is a mobile version here this all this screen here oh this link disappeared then this all these links here would display none why this button this bugger menu would display block here for me to click on it and bring in that this these are done links here so um we are giving remember we are giving an idea of collapsing of collapse so we're going to copy that and paste it here and we just need to change some links here for example the home page let's just say um index that's php to be home and also let's see the users users who subscribe to our newsletter it's not bad in this page yet users.php and also um you know send mail.php this link here will actually be responsible for be sending the user mails sending use the php okay i think that should do it now oh we just as you can see when we reload this page here nothing shows up here why because we've actually not linked it so he said we've not included all these files here inside the the index page and to to do that we're going to go on and go to our move to our index page i'm going to link in through this i'm going to bring in those files here all you have to do is just use our php um method called the include method here or the require wants me to do it so we're going to say we're going to open our php tag here we're going to say php want to say require require once then the those files which is actually inside the includes folder here this file is actually inside the input for the smoke so we're going to say include first the heading because that's what hosts the our html boilerplates method here we're going to copy this paste it in one more time after after that we're going to put in our number live.php and paste it and then our footer php now when we reload this we should get our as you can see we're guessing what was in the the what do you call it go out now for the footer i don't want to make this dark a little so i'm going to give it some style here go go to my style delete all this stuff here create all this i'm going [Applause] remove the bg dark here okay then close it up then save it and we load our pga something isn't working here you know what i'm gonna reload this particular file here which is actually inside the header page i'm gonna close up this i'm gonna go to let's say css slash tile it says just to reload all those files here we load them below them as you can see the footer now appears then go move back reload this page here or simply open this particular page here need new tab paste it one more time reload why isn't that working come on oh sorry another class a futile already reload and now we've got the video um background there so we need to just close up this then the next thing which we need to do just to create our phone here which will appear here then set this footage to absolute absolute of absolutes now when you when you actually use this position of absolutes this sets the position of this photo directly to his parents and it and its spirit is what the body and the body by default is position relative now if we should bring this at the bottom here what we just need to do just to say our bottom should be zero now i'm going to say bottom sorry should be zero pixels now in our body here we're gonna say position um so next line position of relative then also uh i think that's what we need to do then refresh our page now as you can see you also need to specify the left hand side 0 pixels then our width of 100 cents okay now we're actually bringing this footage at the bottom okay that's it guys let's move on to the next one which is our phone tag here so we're gonna create is really simple for me so obviously a very simple form that we're taking the user's um name and email address you know for which send them a an email notification okay so i'm gonna say i'm going to bring in um let's say let's say a div a diff class of what form contents so and also a form tag of form group form group we're going to give it an action of nonsense oh sorry we're going to give it an action of him we're going to submit this to let's say let's just say register user dot php method of posts okay now oh you just need to just give it some of those tags here like the label tag label on the little heading here that shows tag it says subscribe [Applause] to our um newsletter and also eleven we didn't we don't need default m attribute of four here then also we need label of them let's say username we're gonna copy this and pieces one more time and also label attribute for m sorry a little bit of um email okay now we're going to give it an input here of form control by the way all these club classes you see me using it are all in the bootstrap classes so it's not just a magic bootstrap automatically styles all this and dancing all the same tags here with apple print m class okay one control and also a class of matching top two i think that's it next we're gonna give it a name also a name attribute or username okay also i'm gonna copy this one more time paste it in here we're going to set this to em email a name of email okay [Music] and also lastly our inputs type btn which stands for button button class we're going to say btn primary which makes this button here really blue button or let's just say btn info which we create we should give the button here um some like a really dark blue a light blue color or sky blue color then our margin top should be two and also btn sorry btn block which will make the bottom width span according to the container game so i'm going to press tab right now and name this submits sorry so it means i think that's what we need to do for this and also i will give we're going to give the name you know for me to handle this in the back end name of submits i'm refresh this page right now good so as you can see the only goal is getting nice for me but this is not actually table we really need to style some contents here so we're going to move into our css right now and style all this um okay let's copy this this class here copy them copy it sorry then move it to the css and paste it one more time until uh the width of the phone should be 300 pixels the height should be auto which will keep on increasing as the minimap we want to add any other input tags here but once you just hover over the height it gives you more detail but for example it says specify the height of the content area pattern area or border area depending on the box sizing of certain boxes so then next thing we need to do is just to save our margin you just make this from center at the middle here because by the way once we remove our mother our imaging and refresh the page now we're going to see that our form is actually placed in on the left hand side to make it at the center we're going to use our margin of zero pixels auto so margin of zero pixels auto and also a box shadow of zero pixels zero pixels that is 20 pixels at 0. i'm going to use my popular phone from a um my best friend's family here which is poppins okay then refresh the page as you can see it also we need to just specify let's give it a box imagine auto what this is is actually doing now right now is saying hey you and i needed to take in the the pixels here add them to the both the right hand side both the left right top and bottom then center this this clip the same container here at this then place this container here at the center but we also need to add some space here at the top here so to do that we're going to see let's say 30 pixels then specify our padding because as you can see it has no button here everything just sticks at the left or right hand side so i'm going to be a pattern of 12 pixels okay then we use this up uh um this shadow to use it just move up bring your mouse here over it it will color a color palette here we show now all you need to do just to change the color from the club type here so so i'm using the hex collec code here which is ash and the whatever what you need so i'm gonna click on the top here click on it and changes reduce the um the box of the color to this to ash one eight one eight one is then refresh the piece now so as you can see here we basically got this from this um color here i think that's nice now so the next thing we need to do is um next thing we need to do just actually to move into this user.php right now it uses this facebook page here now it creates the same form but this sorry not this form create a bootstrap table which holds all the values here the music doesn't subscribers and also the action if you actually want to delete the user yeah so i'm going to bring in the head and also you know close all this use all these now i'm gonna include all these cars here actually this this should be placed at the bottom of this screen of this phone okay let's refresh and see what's our hopes nothing happen okay then on the user side here all this is going to continue just to contain we actually contain a table if we display the viewer username email and they and some actions that is deletes or some actions actually like delete so we're going to place the table inside the diff tag here we're going to say d the class of table table container okay so this table will be handled in the cs parts here so we're going to give it a bushel stripe this will give it a some stripe and and also a table having a background of dark and stable table having a glass of coba okay now this we are trying to make this table here this cover and class actually we may be taking so we'll be able to see some hovering effect here on it by the way let's move now we're going to say are they heading off table here t-head wait we're going to save t we're going to give some hidden target like th username copy this and this is one more time username email emails again also action action then the t body the tea body will contain the contents of the table here and inside now whatever i'm putting is just temporary we're going to handle this from the lists in which they do fetch those data from the database and list them inside the guru okay i'm going to give the td let's just say john do don't do copy this piece one more time and also give it an email of john dondo as mail.com an action attribute of an a tag a tag here okay we're going to send this to the delete delete user that's php then you know give it an action attribute delete and a class of this table of this text here to make it red do not say text danger just to make the make the text here make the um action to the page here and see what we got as you can see we got this we got this little this nice table here now all this was automatically done with bootstrap i didn't add all this was done with bootstrap okay so let's move on to send me with the php the same way that page will be recording some simple form which will be responsible for sending the user new or any updates if you want to give them directly to their inbox okay so all we just need to just copy out this page here in this particular figure copy it out and move to the same music sensor send me album let's send the php here one more time then move back to our navbar because we actually um we actually make this to this we give we gave this um text here have attribute pointing to send me the php so we actually need to change it to send that php okay so we're going to go into the another php and change it send the php okay and that should do it that's it then refresh back and click on this again there we go this little stop here okay so all we just need to do is to change some things here for example we need we need the user's email we need users period we use but also we don't need it we don't need this here we are really needing is select any custom form control and a class of modern talk of two okay we're gonna give this an idea of um emus emus you don't need an idea for now and also an option attribution option tag here the value will be actually the user's email yeah so because we're gonna say john do as mail.com then the the the text and the text of the option tag will be just will be the username close the email here so we're gonna say join do to use some john doe at mail.com okay because the value should be we don't want to send an email to the username we want to send them send an email to their million not the vision because sending it to their username okay and for this we need the message body yeah message here okay sorry message let's cut this out okay let's see text area having a class of form control pump control there's lots of modern top of two the question is message or let's just say body ninja body we don't need the idea okay let's just leave it like this and change this row to six and that should do it right now as you can see we actually did it go this since something's not right it is okay sorry fro form not from f2 rm okay from control so we can select the username here with the email here and send us a message here okay um i think that's what we need for the second part now let's move into the backend party where we need to handle some details now and by the way this form should be able to submit to a page a file called send me the php so we just need to change this guy here just send others call mail.phpn and the users on the index page you send the ass to register user so we need to create one file for for that we need to create a register user all we need to do now is to connect to our database to make sure we actually connect before anything could happen so we're going to go into our config file and click on the db dot php which stands for database the php this will hold the connection to our database um before we do that let's move right to this our php modern tab um and click on database to make sure we add the database created if not let's begin creating the database okay oh come on so right now we don't have any music okay as you can see we are having music database here we haven't used that database so to create the database all you just need to do is comment type in the name of database and click on create and it will automatically create the database for agent and for the table here we have it using that table you're called this is the data unless you just click on it and let's see some records here okay we have two records i'm i'm just gonna go ahead and empty all this out i'll delete it still here just quit it from scratch okay so now let's move on to let's create a new table here we're going to create a new qb continuing the user because so we're going to say newsletter newsletter table here and click we need if we need four columns here we're going to click on ok now we need to give it some names here and this name is for example we need the id if it holds the id of the specifica um the particular recording added here then we need the visual name [Applause] username we'll send us an email here who's subscribed we'll subscribe to our newsletter here we need the email here emails we're going here so emu then also we need this other dates are dead sorry i did it [Applause] this year but also you want to make this id an integer right here and the length value should be let's just say that's it for now the username should be a text here okay the email also should be a text here then the date should be timestamp this will hold direct this will actually um be inserted automatically once we insert a new record the particular time which we added will be inserted into this column here so you always need to go is to scroll down and make click on timestamp you could choose a new one yeah which is at this time timestamp before this always timestamp here then for id we need to set on a primary key for it right now and and also increments um type yeah you know for it i did to keep on incrementing by one whenever we add a new record to it so we're gonna click on auto implement here okay and we'll click on okay here then node index here and that's it guys click on save and our new table has been created okay now there it is click on it on browse okay as you can see here right now we have no records there on it so all we need need to do is to go into our database here and for this um tutorial i'll be using the procedural step here enough force to connect to it using mysql okay so to do that let's move on let's open up page tag here php then for this um for database not for it connect to it we need four four things there we need the look the local host which we are running on which is actually locals sorry being this server which we are running this on which is actually localhost here then also we need the user the user here then we need the root and the password and also the the database which you're trying to connect to okay so we're gonna set them i'm gonna say let's say localhost here [Applause] sorry and in php a variable we started which with the underscore sign here localhost here i want to give it a value of local hosts and by oh yeah every php variable must be closed with a semi colon here otherwise an unexpected em error will be tuned to you so we also need the roots which would be automatically the user by default then the password password for now i just set it i to this database all we just need to do is to let's say connect to db using mysqli connect connect method here so we're going to say connection is equal to mysqli and let's go connect now this might connect once we overview this um this method here um this method takes in all these four values here which we've written so all you just need to do is just to specify that inside the cases here so we're gonna say on hosts comma our roots which is the user by by the force our password which is known in our db okay now we don't need to check if actually our database is being connected here so to do that we're going to use some control flow state let's say which is the if statement so we're going to say if this if this connection here works copy inside here if the questionnaire works you're going to say echo connected okay then die that means it will stop any other scripts from working here or equivalent to exits um metadata so we're gonna see that else if it's not connected you need to say echo not connected not connected okay then i should die now oh all you just need to do just include this final index pdf and see what it gives us okay so now next page here now next page here let's include the file here i'm going to include it at the very top of the file here of any other php including tag here so i'm going to just copy this from here it's at the top here and go to our config folder because that's what the values and select the db dot php then reload our browser and since what as you can see said mysql connect as is not for user okay sorry the root should actually be roots by but it was so we're going to change it to roots but if you have a username set you need to put in your username or your password here okay then you go to this page here as you can see it says connect it and once it was connected here it didn't show any without m stuff here really hard this takes you with a blank pj that's because of this diamond metadata it stops in any other scripts from working here so all others need to do system that we are creating just comment out all these thing um echo statements here and refresh the page right now okay now systems now just go on inserting those bodies we got here from the the phone tag here the form the form here in the browser here okay let's move on to so let's close this file here and as you can see we actually we are sending this from here using it we are sending the form value here using a post method inside this to this page here so we'll be able to grab them from that and script file name so to do that let's open this page here called register user.php okay let's set up php opener tag here php then we're gonna say some if statements really want to allow users here to come into this page here only if this submit button here is clicked if you're not click without them back to the index page so to do that let's just say if it means if and else here so when i say if it sets now it says means it determines if a variable is is declared and it's different than no we're going to say if it's set posts remember we're using the post method so we're going to say if it said posts or whenever there isn't a guess when in fact let me mention this when sending any values from from the fire to internet file it's called a post method but when fetching it give it away from me any other um failure or server music gets mentioned here so we're gonna say if the post submits and by the way submit is actually the name of this attribute not actually the text here but the name here so we're going to go back let me show you what i mean if we give the name of submit so we're going to say if this post submitter is clicked then echo out hey you click that okay then die here the else big gonna say echo trying to hack okay like a guy here now this will be used it just guessed it so once i click on on this page here it says hey which means we click on this page now let's click on back here but what if the user tries to go into this page here we just clicking it let's see what we got him so we're gonna see when he start sorry register user not php and we're going to say trying to work now by the we have really got this because we saw we use the echo statement but we don't echo these are these we want to redirect the user back to the home page yeah not to do that we're using some head up method here okay we're gonna say header there he said header it takes in now the the function of this header is that it sends a row it is to http and then it takes in two but it takes in a string that is the header or a boolean so for that location location what do you want to direct this user to you want to directly this is a back to the home page and the home page is in the file called index.php so we're going to say index dot php and stop any other script from one there okay now since we came into this file without clicking on the button let's see what how it goes so we're going to refresh this page here and boom as you can see it's videos back to the home page if we try again if you try accessing that file name register user it's very backwards but when we click on the submit btn here as you can see it gives us this um message here okay hope that's understandable okay but we don't just echo some some stability we need to one we need to validate user by this user inputs here and after that we're going to insert it into our database here it sat into dba okay but to do that we're going to grabbing this to input here namely username and email okay so just so we're going to get our variable here we're going to say username will be the postman because basically post um the posts metadata from our phone so we're gonna say post username sorry about okay across the username then echo out the email okay so let's just fill in some stuff here submit this and you can see we got the email here we got the name and the email here okay so now since we know that since we know that this is working we want to start the validation stuff so now we don't want to actually click on this button here without filling in the message j otherwise if they do so you want to display an error message here in this in this particular pda on the phone okay so to do that we want to use some if statements here we're going to say if if empty empty which is referencing the the inputs here so you want to say if this if the username input is empty or the email input is actually empty we're going to do you want to direct the user back to this page here and display an error message on this form here to do that we're going to save we're going to copy it out here paste it here okay then remember to display an error message here do not put in a question mark here and this whatever i want here arrow is equal to the messenger fields fields cannot be empty okay now else if person want to validate the user inputs here so we're going to we're going to say else if filter when that's called now this method is used to validate emails so we're going to say you know if this email here the particular email is here he's not isn't correct i'll be using some filter and [Applause] now this method is used in yeah and you want orders like you you are able to go simply use that soon use the uh defaults and filter menu there so we're going to say if the emoji entered here isn't quite you want to be directly back visa to the home page and display an error message here so do that do you know copy all this from here paste else if everything went well else you won't gonna insert this record those records into the database but before that we're going to put this inside a image called mysqli real escape string now what this does is that it's actually escape any string any sql statements been inputted here inside these feeds so for that for example attacker tries to get an info from our database and putting some sql statements here this function this method will automatically escape it okay so you certainly need the connection to a database and also the bottom here okay and also these two i'm going to say mysqli real escape string then the connection and also the value here now for the connection don't bring it in so we're going to require once the ground once then sorry go to the config folder then select db.php file here also not dbv db dot ppg file here okay if this if all this went well we want to insert the data into our database now to do that basically we're going to be using some l scale sorry sql statements like this select statement sorry the insert statements and some um um this select statement so but this select statement will be used in this particular file filename so to do that we're going to say statements is a question remember always close your various name you take coulomb okay so to do that we're going to say insert into now this takes in the table name here and the table name is actually called what newsletter user tbl okay and inside this table it takes in the column which we want to insert the record inside them so if you want to insert this record inside the email here email and the username here sorry the username and email here username and also the email here was look up inside the table here we've got the visa name and the email here okay then it takes in the values now the values okay the values should be inside a and the value should be the variables they need to get up here those input values here so you're going to copy them paste it in here also copy this and paste inside this place here okay then we just want to query this this statement here okay we're going to say query i'm going to say mysqli query this statements here now when we query statement j it's actually mean we want to like make sure this statement here um and it could it's been as a clearing successfully so we're going to say let's like query now this query and method takes in two m parameters namely the connection to our database and the statements we are trying to query now we're going to put in the connection here and also the statements here and don't check we have this statement is is successfully executed what what do we want to do so we're going to say if if query went well if the query went well okay the query went well what do you want to do you want to direct the back to the home page and display some stressful messaging okay now we're going to change this to message here msg and say and say um thank you for subscribing to our new letter okay else if you didn't go well because i want to give you some error here saying hello say please sorry something went wrong [Applause] please try again later okay and does it we are done with these parts now so all we just need to do is just to guessing all this error here from the index page the arrow and the message the arrow giving a class of red of text danger to make it read why the message will be giving a class of text success to make the color here green so we're going to go back to our index page here and give give some pizza here but before that you want to put some con condition there a place with condition here we're going to say php if if it sets that is if this particular variation gets now get is actually used to get images coming from the server or first or from some filing if the all the from the you are here the you are from the navigation bar is gotten that that is this error here this area will be passed in from the base that user here is actually um sets they want to display a message there okay if it's set if also he said get this message here don't display some stuff it's awesome okay php okay you want to display some p tag here on the speed tag we contain a class of texts get arrow here okay then close it um coulomb this one do the same thing too with this um message here but you want to change the color to green so this will be success then change this to msg okay now let's test it out and see what we got first of all where's the page now refresh the page and let's see if you didn't need to argue and she said syntax error unexpected and called um calibration exporting end of fight in indication online 14 so going on line 14 so what's wrong else if okay sorry opening quality so let's refresh again and see what we got come on why is come on okay sorry guys about that it was actually for some taken card and difficulties here from my software which i was getting and recording this okay now so i'm back with this now so in the previous time this page was actually doing now let's actually try to test this when this let's try submitting this phone when this 2m inputs here i empty and see what we're going to get back okay let's try using the submit button now and it says field cannot be empty now let's try putting in some wrong details now okay so i'm gonna dot com and submit it again and it says email giving is inverse that is where this function now this method now is actually working it's actually trying to validate the email okay now let's try putting in some details now okay let's submit this form now and say something went wrong please try again i mean we need to try to check for the arrow we're just crossing this okay let's put this on the same line and see how it goes then our the values here contain only the ones that continually is missing some quotes here so we actually need to change this now okay let's put in this single quote and refresh and try to submit that form again let's go to our home page back and try submitting the correct details here okay let's submit it now and also say something went wrong now something went wrong this query went with our connection and the statement inserts into newsletter table username email and the values here this and this okay then oh let's try and figure it out using let's try to see what we've got in our table here you know table you know database let's try seeing getting it right and see what's happening next okay hope you guys saw that nonsense okay now let's try sending it again and see what happens okay quick quick then our name our email then submit and boom it says thank you for subscribing to our news letter and let's move into our table records and see if if the bodies right we actually inserted into this thing here let's refresh this okay as you can see we got the values in our table here using all these codes here and certainly this about validity okay that that's that is guys in the next tutorial we're gonna be displaying these records here in the user's em page here hope you be writing back or should we just do it now um what's the time the time is three four two three i meant to stop this by four okay you know what let's just quickly do this you know newsletter in our users to table so now heading into our users and page now let's display those records in this thing we have some action for it now to do that we're going to require our database connection to do that so let's move in sorry let's copy all this let's require this okay now you just use this php i'm also going to put it there okay like that's then this place here okay i'm going to say um i'm going to write some sql query here i'm going to say um let's say a statement is equal to now the escape statement which we're going to be using here is actually the select statement we are trying to grab data from our database table here so the right statement for that is called the the statement oh and so let's we're going to say select all now when we use all here barely use the star symbol here or whatever you call it so when we say select all gender from select all from our table called newsletter newsletter tbl okay you set off music this statement what it's trying to do is that by saying you are speaking to the database say hey i want to give me all these records in your your um table here and bring it in into my application here okay hope that makes sense now we have to query this for this to work you're going to say mysqli query okay so we're gonna it takes in two two parameters the connection and also the statement itself now when we use select earlier it returns an asset of an associative ovaries which takes um which format we need to loop through those arrays and print out this um the formatted data now just to show you what i mean i'm going to put in here the result here is equals to mysqli now for me to fetch the data from this query here use the mysql fetch or or mysql fetch a source fetch our search so we are putting as an adjective over here now let's print out this and see what gives us we're going to say um print out into printing out this then let's just see what give us okay as you can see it's actually in an area when we look at the source code here to present it in a more formative way you will see that it puts out these aren't keys and values the id is equal to one his name is equals to quick quick email is this and they added it is actually the ccm okay hope that makes sense so now for me to do that now we're gonna look through all those data then grab them and insert it into this the same table here so let's try doing that now we're going to use the white states the while the while loop to do that so the while it goes like this why i am take notes the while loop runs if a specified condition here is true so once this connection here is is what is connection here is true the following and down below okay php here then close our why look tag our while now since we're bringing in those data we're going to get the username i'm going to get the journey we're going to say php sorry php echo the results remember it is an give me the username from that result here okay then copy all these two copy this paste it in one more time we're going to get the email and finally let's add a td here cd to display the dates okay then this we displayed added added ads because that's what this video is the other okay sorry add the dates no added arts are they dates then finally our action yeah by the way we need to i'll add another t table head here for it for this value for this um the next td to show to this place we're going to copy this and paste it one more time then add our table here sorry um dates and let's let's let's let's see if this works now you know refresh the page and boom we got our username quick quick the date which it was inserted and it deletes um the action here how did is going to be inserted into we're going to send the action here the particular um when is that click on this delete you want to be able to uh take the user to another page run on sql statement to remove data according to the particular ide then we redirect us to these same pages and give us a lot saying um so subscribe user already deleted now we should do that we're going to create another file here called delete user.php copy name here then head over to this and then tab then click on new file then enter here okay so now this friday will be we only need the we need the um require statement so the database connection here okay so we're going to require that php require that i'm gonna say um now for to delete this but we have to go back to the php and put in an extra parameters called the id the particular id here so we're going to echo that here the particular id of that of the newly added subscribers here so we're going to say press and give us the id from the database okay that that's a particular idea now in this page we don't want users to come here and try to delete any recorder from this bit in this page okay to do that we're gonna say um if and else okay if it's set remember i said grab an echo from the prominence server or from the url use the and gets the and sorry the dollar and that's called get superglue probably grab the data from the url so we won't if it sets we want to guess we want to say the particular id is equal to get that id okay then you want this one to run on sql statement here that deletes the record based on the ide so for this statement say we're going to say delete delete all so it deletes from newsletter tbl where id is equals to the particular ide given id okay now the query goes mysqli query okay and it needs the connection and also the statement here i want to say if the particular query is correct if this query one run source volume beyond the and message here say successfully deleted user okay then die here also else we gonna say copy all this guy here copy this guys paste in what i'm going to just um putting some arrow here and say and something runs wrong okay so that's what we need um and for this else statements there is a back to the index pda i just if this um if this id from the from this and from the url is not set okay one of the user back to the home page here index dot php now okay now from let's move on to index pga and copy this if statements here we can show some alerts then the user.php and add the alerts here after the number okay putting some this condition here that is if that particular ids if those parameters are set now we are saying if the error your message is set display the particular error need tag having a color of red then if the message um parameter is set in the url you want to display a message with a class of success which will make the text green or blue but since legends use an a custom bishop that's called d they're gonna give the class not text danger now but an alarm class and a lot did you just create a custom um box here having a bagan of red okay change this to um alex alex success okay now let's let's refresh the pitch and hopes nothing goes wrong then let's try building this visa now and it says successfully deleted the user and as you can see we have no users now in the table let's go back to home and enter so subscribe to another um email here thank you for subscribing so let's try another one here now there's something i want to show you guys now when we add a particular email here which exists in the database no error is true okay now now good let's move on to the user consider this particular email here exists in the database so we want to prevent the user from adding an email which is already in the database record who is that clear so in the next tutorial we're going to be doing that we're going to be doing um we're going to be writing writing some scripts that we'll be able to we allow us to send a bug email to all this registers user okay now so thank you guys for having me here so in the next tutorial we're gonna do that thank you
Info
Channel: Benrobo -Tuts
Views: 932
Rating: undefined out of 5
Keywords: javascript, jquery, mysql, php, sql
Id: _paEEWwvYuQ
Channel Id: undefined
Length: 81min 30sec (4890 seconds)
Published: Fri Feb 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.