Send Friend Request & Notifications - PHP/MYSQL Projecr Tutorial with Source Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right youtube in this video i'm going to show you how to send friend request from uh one law one user id to another user id so this is the two login screen i'm i have opened it on one in incognito mode and one in general mode so let me log in first and show you i'm going to login with david email account login so if you click on timeline so this is david and david is going to send a request to john so let's log in with john so this is john so now david is going to send request to john so for that what david has to do is for i have created this with the help of php mysql and ajax so now the david has to get into the john profile david let's get into the need to get into the john's profile and he has to send friend requests click friend request and it says from david's timeline we have sent friend request to john so if you see friend request already sent now we are in the john's profile now in another tab if you click on notification you can see david send you friend request and in the next video we will see the accept and reject functionality so if you did not understand what we are going to do let me talk about and show you again and and in this case i'm going to login with paul and here it's going to be matthew so on the timeline you can see this is paul and this is matthew and paul is going to send a friend request to matthew so for that paul has to get into the profile of matthew so let's get into the profile of matthew and powell is going to send friend request friend request is sent and if you click on notification and you should see paul has sent you friend request so matthew received the request so in this case if there is no request powell is not going to get so let's send the request from matthew to paul the idea of paul is too so if you click notification again you should see now before that you have to send friend request friend request is sent now if you click on notification now the paul will get the notification from matthew fine you are clear i believe you are clear what we are going to do in this video so the whole section let's work on creating the friend request notification section uh fine to follow along i have left the source for the description fine follow along let's get into this so let's create the timeline so if i login if i get into the register.php and get the username and password of the account which is activated click on submit now you can see this is the profile now the timeline is not working so let's add the timeline open the inc we have header and inside that we have timeline so let's create a file called timeline.php and we need to pass a parameter called name or let's say id equal to will pass the station php echo so the session which will be created after login which is member id fine now if i refresh and click on timeline the id we can get it so let's create a page called timeline.php click on enter and now let's copy paste what is there in the index.page index page so if i refresh click on timeline and it says it could not found the file let's see why so if you see we are saving it over here so we have to save it on the root directory that's the reason we could not get it so let's open which is in the root directory ctrl w so if i refresh we could get now just by getting the dollar underscore request and if i get if i have id and install it into a variable called dollar id i have not used the php yet so if i try to echo the id refresh it now you could see 11 is available we don't need the lockout button now with this id we have to select all the values from the profile.php so we are going to use a select statement which is available on login.php or we'll get it from in the profile.php actually we have used the country so there we have the proper code just copy this and paste it over here select star select everything from the table profile where id equal to you can see there is an id actually it is an user id not the id where user id equal to the id which we got from the url single quotes dollar actually we don't need while loop here since we know we would be getting only one row that's the reason so here sql profile and now with this variable it's an array we can get all the input field so we can get all the column names if i try to echo about i should be able to get it remove this id refresh now if you see the about is available likewise i'm going to get all the values gender data education profile pick this much refresh so with now this it's time to store this value into a variable dollar about about gender date of birth education profile and now let's create row and here for sidebar call 4 and for diamond and status message call 8 and inside that again i need row call 6 which will be label name likewise this is for about gender data birth education and we'll have profile picture at the top so let's echo the values let's see and it is available likewise gender birth education and now to get the name we need to pass this to the different table which is registered and this time it's really id and from this result what we need is we just need name and email so let's me check the column name on the disk which is this we have id name email name email and that's it get this name and get the email and if you want the name you can display the name over here actually the name here is small case let's fish online button so this switch is switch is remain we have missed the function mysql underscore fetch in this query which will convert the array into name index when we got the name we got the about we got gender we got date over then we got education let's add the image as well mix tag in the images folder let's pass up refresh fine now you can make text center if you want you can design as you like so let me add padding top margin top of three let's say five and for the image padding bottom of five or let's make it three fine now we are able to fetch the values log out and let's try to log in with some other details here uimonk login if i click on timeline you are seeing the profile picture along with the data which you have inserted while editing the profile so let's make this image size little smaller height 300 with 300 or if i make 200 and 200 that would also be okay log out let's try to log in with the old one timeline yes i could see all right now let's see how to create send friend request functionality so for that we need to create a table request just save somewhere and we need id sending from sending to and then accepted and then date it fine click on this is primary key sending from sending to accepted is going to be an enum zero or one and then date added is going to be date or time click on submit table is created now let's add a button so here we are going to add a button call 12 padding top two class we already have bootstrap btn btn primary and on click here send action here the first i'm going to pass a constant value and then i'm going to pass the id which we get here which is this id php echo now let's define this function at first it should just say hello to test whether our jquery is working i clicked but it is not working let me see why let us make this double quotes since we are using single quotes outside so let us make this response here click on submit and you can see our jquery is working and let's see the constant value and the id we are able to fetch if we click on send request we should get the id 11 yep we are able to get it ctrl o fine now we are going to use uh jquery uh ajax dollar dot post and here the first file let's create a file handler and the file name is going to be action.php and here we need to pass id equal to the id which we get here just try to use backtick fine and action equal to send request so after the second parameter we get the response and will alert the response so now we need to create a file a folder called handler so let's create it on the hd docs social network handler and inside the handler we need a file called action.php and we are passing the id and send action so let's try to check create a php first echo hello now let's see whether we are getting hello use of undefined constant hello so we are getting the hello we are using it without single quotes that's why we are getting this error i guess yellow is available now we want to show this hello only if the action is send a request if is set dollar underscore request action equal to if we said dollar underscore request action is equal to send request then show hello let's see what is this error let us remove this set now if the accident request will get yellow that means it is working fine now let's get the id from the url dollar id so this is the id of sending sending to request sending to request sending to and request sending from is actually from the member who is actually logged in dollar underscore session and here we have set the session as member id so now we got sending to and sending from now it's just time to insert it so for inserting we have the query already set here so here the table name is going to be request sending from sending to that's it the date added so here the sending from request sending from sending to and request sending to date added is going to be to date single course y underscorium undiscovered fine now i believe everything is okay now once we click on send request the data should get saved into database and we should get the message data requested saved into tv let's try in the request table that is bank right now if i click on submit the id both of them is going to be 11. but we have not used two values which is the first one is config and second one is session start now refresh it let's check whether there is no value inserted click on send request and it's the file path we are in the folder called in handler send the friend request click on browse yes we're able to send request we are not echoing the success that's the reason we could not see click on submit request sent and saved it to tv now you can see values actually we are sending from the same id we are sending request from the same user so the user is 11. we are sending the request to the same user 11 that's why we are getting this so in case if we have another user let's see the another user let's take 10 and open that value so this is another user and my current logged in id if you remember is 11 click on send friend request now you are able to send so now the tenant will be there evan is sending friend request to 10 so we are able to fetch the values so we are able to send request to another so here in this video we are going to see once required sent do not show the request button do not show that send request button likewise what i mean by that is if you click refresh if i send request now if you browse there are actually six values click on send reference list so at present if you know we are sending requests to our self so if you see two values are inserted that means we are sending requests to ourself that's that itself is an wrong thing the second thing is the data is getting inserted multiple times to stop that what we're going to do is we have to get into the page called timeline.php and we will be getting the success message from the file called action.php if the success message is this if response is equal to this then what we need to do is we need to hide the button so how we are going to write let me give this an id using jquery dot height let's try to sell request again after success you see the button gone so i don't want just the button to get disappear instead i want to have a text dot parent dot html request sent so what it's going to what it's going to do is it's going to get the id from the id get the parent which is this one and inside the inside this what we need our text is we need a text called requested successfully now if i click again you will see request send successfully text and that doesn't stop there the data is getting inserted let me refresh it and uh on every refresh if you see this data is already there but the button is available so to stop that we need to add a condition saying if we need to run the select query let's add php block check request select star from request this is the request table where send from send from here we are going to have some values and send to 72 is actually the one which is currently locked in and accepted equal to zero so send from is going to be the send to is going to this section which is which we can get ctrl f sc css session is not there so let's get it from the log out this is the session sessions is already available so we don't have to worry actually sending from someone who is logged in there is a mistake let's see what it is yep if you see we have already double quotes here that's the reason it is not allowing us and we cannot have single quotes as well so the best thing is concatenated the same way here the sending tools will be from the url in which we are viewing if this returns at least one value then the request is available on the database we need to use numrows the code is available copy it if we have one at least one result then we need to have a text called request already sent else that means the data is not available on the database so for that we want to have button that inserts data into the database so at present if there is no error the 11 is already there in the database we should see the text on line 73 except one parameter sql result so first we will try to echo these values to check whether we are properly getting the values from the session and from the url we should get it fine we are able to fetch it now let's try to have the hardcore value 11. sending from and sending to so we are making some useless errors actually it is request not register so the data is already there then we should not get this button but we are getting it let me see why the thing is we are getting nine values if you see here nine it is we are not getting one we should see if it is greater than zero then uh if you notice i have replaced the values hardcore value and test it to avoid semicolon single quotes and double quotes now we don't need this as well now let's try request already sent so if i delete all these values and start from scratch that means start fresh there are no requests in this table they did this so you should see the button so if you see if i click send request request will be sent request send successfully and if you click on browse data is inserted and after refresh request send successfully is not going to change so like if you like to change if you like to give request to some other guy let's say 10 on page load is this it is showing send request because on the request there is no such request if i try to send request and you see request sends successfully and is inserted sending from 11 and send to 10 if you refresh the button won't be visible the text is available fine that is working now let's get into the next in this video we are going to see how to send a notification for friend request so i have inserted some values so let's try to log in with this guy a guy named john you could get into prof timeline you see i'm logged in as jon but john cannot send a friend request to john itself so for that we have to add a condition here if my session is equal to the id which i received from the url if both are same then i cannot send friend request to me to myself else i can send friend request so now there is there will be no button so if i get into some other user let's say eight let's see eight get into eight now i'm logged in as nine but i'm looking at profile eight so at that time i can see the friend request button so if i click nine now i'm myself if i click 10 so this is another friend so i can send him friend request fine that is working so if i click on now i am 9 i am sending request to 10 send request and you can see on the request 9 sent to 9 sending to 10 so that is available so i am logged in as 9 so if i refresh now you can see there is no button and let's work on the notification now so for that i have to create a table so that table is going name going to be notification we are going to have six columns let me add two the first one is id which is going to be auto equipment the second one is notification 4 and notification 2 let's make a notification from and this is message and we are seeing whether it is read or not and then we are going to have date added so this is id id int and this is going to be where care 200 and this is going to be enum either it is going to be 0 or whether it is going to be 1 date added is going to be date and time and if you notice this id we are going to add this as an auto increment so if i click here it will be selected as primary key that is what we need click on save and the table is created now while inserting like on the actions.php control p on the action.php we are inserting the data on the request table likewise i need to add to the notification table so here the table name is going to be notification and notification from notification to message we will make it in a minute is read by default it is going to be 0 and the date added which is the current timestamp which we have already created all to set so notification from is simply the request sending from automation to is request sending to message will create it dollar message equal to request from which is id is sending has sent request to request so let's add this message and it's read as i said it is going to be zero and date added is here we are we have used php function fine now if you see let's delete this on the next nine cent front request to 10 we don't want that so now we can see the button let's check the notification tab as well open new tab so what should we exactly consent request two data two tables need to be populated the first one is request and second one is notification if there is no error request send successfully so nine send friend request to 10 nine sent friend requested same on notification actually i haven't write the quick and let me write and sql notification now we're going to delete this and we can see the button again send reference request to data to table a to be populated cent nine to ten and nine to ten five you can see nine and request to ten so you want to decrypt you can do it just by using the sql query for these two id for sending from and sending to so how we are going to do it use a select statement which is available over here we need to get the name so to get name name is available on profile now mr yeah name is available here if we have to get the table register where we get the i'm going to get the name where id is equal to the request sending from the so this sql is simply request from name the same way request to name here it is going to be sending to so now after executing these two queries so how are we going to execute from passes to and we have to use a fetch associative array which is available here name underscore from name underscore 2 and now you can see 9 and 10 so let me delete this and on the request let me delete this you can see the button click on spend request line sent browse there was an error that would delete let's check again it's an associative array we need to get the row and that row with that row you have to get that name column so let me delete all these values and so now it's taking some time click on send friend request and on the browse nine send print request to 10 and on the notification tab john has sent friend request to ui monk fine that is exactly what we need but it has been inserted twice it is because of the browser so i am logged in as nine so let me make let me get a value eight send i'm nine the name of nine is john john is sending friend request to david click on send first let's see the request nine sent to eight and john's has sent request to david fine now we are able to see or we are able to add the message to the database now it's time to fetch the values on the new page let us create a new page called notification and we'll display over there so now we are going to show notification on page so for that we have to create a page on the inc we have header let's create one more link notification you can see notification is available here notification.php so it is going to be like index so here with the help of session id we are going to fetch the values from the database notification we are notification and if the two matches our session id then display the message that's what we are going to do so the select statement which we can get here sql for notification dollar id so this id would be passed here the only change is the table name and we need to run the query after running the query i want to fetch the value and after fetching the value i want to echo the column name so right now we are logged in so there won't be any notification for now john sent friend request to david actually we are john and the david it is not id it is notification too we are we have sent request so there won't be anything so let me remove this logout which is not required so let's see this is john send request to 8 and 10 so let's see who is 8 and 10 on the register 8 is david and 10 is ui monk so it is david let's log in with the david account so now here we have to click on the notification we should get that john sent notification to david fine now let's check the ui monk also which is this and now you can see on the notification john sent request to ui monk so let's design this so if there is more than one uh if there is more than one uh columns in a table or we need to run a while loop so let me run the while loop now so the while loop will accept the fetch associative area now let's try with multiple values we have to echo fine we are logged in as ui monk so log out let's sign in by paul and send request to ui monk the ui monk id is 10 get into the timeline and pass 10 send friend request log out and log in by ui monk you should get two friend requests one from paul and one from the guy which is we have sent earlier john and paul fine that is working now let's work with some bootstrap classes to make it a little attractive so here let's comment this this is how it looks so what do we need is let's create a row dollar row call 4. call eight and this thing will be outside php now if there is any value it should be displayed inside the call it fine copy it is working now here we will use something like this alert copy this paste it and paste this over here using the php now if i see john send request to uimonk paul sent request to ui bonker so let's write this inside card card body inside the card body let's have this fine now if you see these two guys has sent a request to paul so we need to add a button here like accept and reject so we have to send this with the database itself on the timeline we have clear we have created a message here so here with the message we are going to pass two buttons button class btn btn primary and it's going to be accept the same one is going to be reject so let's try to second now let's clear all the values from the rift to avoid confusion delete right now i am logged in as ui monk all right let's delete the notification check all as i said right now i'm logged in as ui mock let me get into powell's id or 10 is actually ui monk nine john eight seven so let's send this request ui mock is sending request to vishal send request on the request you can see it has sent now let's login with this guy vishal the id is seven seven this is vishal html.com and on notification there is no values let me see what is the issue that caused it let's see on the notification whether we have inserted some values on the notification it is blank that's the reason okay we are now logged in as we saw let's try to put request to some other guy let's see it visually sending request to david i'm clicking it but it is not working let me see why there will be a php error on the action if there is any error it should be this which is causing the success matches not showing up maybe this is causing it let's try to remove and change it test it refresh i think that is it let me try to delete it and start from try to send it again and yet notification is not filled check all delete refresh click send request and on the notification it is available on on the accuracy request let's try on the notification motivation is also available so the thing is this is what causing the problem let's try to make this on a single line and check alt z control b or that could be another issue as well click on structure instead of where care change change let us add text click on save and now let's delete these values activation is blank and request is also going to be blank david vishal is sending requests to david click on send friend request mouse on request data is available on notification data is not filled our notification data is not filled because of this causing the issue i think it is not allowing the let us not try to append let's try to append here dot equal to so this is another way let's try now motivation is black by default let's clear the list refresh click on send friend request on request data is filled and on notification data is not built this is causing the issue so let's try to mysqli underscore error dollar connection remove this you can see the button now click on submit if there is error i click four times notification is blank request should be blank but it won't be the thing is notification is not getting filled so the very simple fixes you have to write back ticks starting from here click on browse delete this there should be data that still it is as well now we are in seven visually sending requests to david send friend request request sent and let's log in with david id and on the notification i could see one lead off let's see the notification this should not be the case let's add currently dish let's add this inside now let's try to send request now david is a request to vishal request is sent about notification message is not sent we don't need this let's try backtick dot has sent you friend request yeah you have option whether to be no renter let us delete check all delete refresh it is sending request david is sending requests to vishal let's see on the notification table what messages holds we just have david we can see only this this thing is not getting saved and now let's check now david is sending a request to vishal click on send request now let's login with the debit id and on the notification we should get let's see what is the notification field here the data is filled on the notification let's get into the id 7 i believe the name is vishal gmail.com let's check let's go check there could be a mistake yes it's visual now on the notification we should see two buttons accept and reject oh this is what makes us made us so difficult that's not that's okay we can do it fine on the notification page we don't need this one now on the notification page alert t flex justify content and between fine no issues now we are able to send the request with the button accept and reject so let's add functionality to this button and while passing the message we are going to add on click listener equal to and it is going to trigger a function called request action it is going to have parameter if it is one then it is accepted request is accepted and if it is two request is rejected and along with that i need to pass the session id who is actually logging logged in oh it is not allowing me let me see what can i do let's type that is wrong we'll do some other thing no issues the only way to test the standard request again let's delete delete on the request check all delete now actually seven let's send request to let's say 6 friendly question let's login with matthew we shall simply request to matthew we shall send you friend request now we just have to notice whether on click we are receiving the session of the patch sent the request it is going to be id of course here it is id string so it has taken as a string that is a mistake we have to make it as in number so now it was not backticks it is single quotes let's delete and on the register as well so not on the register on the request now matthew is going to send request to sending request to vishal log out log in with vishal create gmail.com now matthew sent your friend request now along with that you should get the id and if you see one and six two and six one means accept two means reject so this can be accessed on the notification.php and here on the script you are going to create a function and the function name is click and here you are going to get two parameter which is type either one on two request or reject and then the id of someone who has sent the request and let's try to alert it here it is going to click on it is one and it is two and you send a friend request it is going to be because your current pick is system you have received from the six it's a friend request from the user six fine now we are going to post our hx dollar dot post the first one is the url handler slash action dot php and then the callback function whatever response we'll get will get and alert the response without fine now here we have to pass a string called name equal to question mark name equal to request section just to identify whether we are in which section and the second one is the request sent from equal to use the we'll use backtick now and with this we can send equal to now this is an id and then the type either it is going to be one or two now we can access this on the action.php which is this one and we have already used the if condition let's see where it ends there is no formatting html here so here it ends else if the request here is going to be the name which i have sent dollar and on the notification.php here's action the name will make it action action equal to request section if this is set then echo uh some message let's click either one button we should get processing and on line 7 there is an error line 7 undefined index action actually here we are passing it as let me replace this ctrl u on the script we are passing it as name refresh let's see the script here here we are still passing it as the name so we have not saved it click on accept processing click on reject processing we have to perform will do it will perform we are going to check now so far you can see you are able to send a friend request and you are able to receive the notification of the request sent and now we are going to create the functionality of accept and reject
Info
Channel: UI MONK
Views: 1,349
Rating: undefined out of 5
Keywords: Php mysql project from scratch, php mysql project tutorial with source code
Id: Rf4gFHhUaz4
Channel Id: undefined
Length: 80min 0sec (4800 seconds)
Published: Thu Dec 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.