From this post, you can learn how to make Follow and Unfollow system like Twitter which you can create in PHP using Ajax jQuery Mysql and Bootstrap. There are many viewers has requested to use PHP to build a Twitter like system. If you know on Twitter can post short News in Tweets format, and that tweets will be visible to those Twitter user who has follow this share user. When user share any news or tweets, that will be visible to his followers. So, this type of system we will make in PHP using Ajax jQuery and Mysql Database.
IF you are looking for any Social Networking Application for you colleage project, Then this post will help you to make small Follow Unfollow Application in PHP using Ajax step by step. On every publish of video tutorial of this post, you can find updated source code under this post. So, here we will show you How to develop twitter like follow and Unfollow system using Ajax in PHP script. Because most of this Social Networking sites are make in PHP Ajax. Here we have also use Bootstrap library for CSS purpose for make this system. So, here we will make dynamic follow unfollow application in PHP using Ajax.
Following are the main functionality of this follow unfollow system.
New User Registration
Login form for registered user
Authenticated User can edit his or here profile with upload profile image
User can share post, and list post
List User with follow unfollow button
Display number of followers of each user
Main functionality is to follow or unfollow other user post
Display dynamic results will be display if user click on follow unfollo button
All data will display using Ajax without refresh of web page
If you user follow any user, then he can also unfollow that user again
User can view follow user post on their timeline
User can comment on other user post
User can view comment on post
User can repost other user post on their timeline
User can see how many time particular post has been reposted
User can like other user post
User can like particular post only one time
User can view number of like on particular post
User can view username who has like post in Bootstrap tooltip
Share image or Video with Post
URL Content Extract with preview
Search User feature
View all post of single user on one page
So, Above are the main functionality of this follow unfollow system in PHP using Ajax jQuery Mysql and Bootstrap. Below you can find source code of Ajax based follow unfollow system.
Run follow SQL script, it will make three table like tbl_twitter_user, tbl_samples_post and tbl_follow in your PHPMysqmin. Follow Unfollow system has been use this three table for make application.
CREATE TABLE `tbl_follow` (
`follow_id` int(11) NOT NULL AUTO_INCREMENT,
`sender_id` int(11) NOT NULL,
`receiver_id` int(11) NOT NULL,
PRIMARY KEY (`follow_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
CREATE TABLE `tbl_samples_post` (
`post_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`post_content` text NOT NULL,
`post_datetime` datetime NOT NULL,
PRIMARY KEY (`post_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
CREATE TABLE `tbl_twitter_user` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(150) NOT NULL,
`password` varchar(150) NOT NULL,
`name` varchar(150) NOT NULL,
`profile_image` varchar(150) NOT NULL,
`bio` text NOT NULL,
`follower_number` int(11) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
CREATE TABLE `tbl_comment` (
`comment_id` int(11) NOT NULL AUTO_INCREMENT,
`post_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`comment` text NOT NULL,
`timestamp` datetime NOT NULL,
PRIMARY KEY (`comment_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
CREATE TABLE `tbl_like` (
`like_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`post_id` int(11) NOT NULL,
PRIMARY KEY (`like_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
database_connection.php
This PHP file is used for make database connection. This is common file which we will used in all files for make Mysql Database connection.
<?php
//database_connection.php
$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");
function Count_notification($connect, $receiver_id)
{
$query = "
SELECT COUNT(notification_id) as total
FROM tbl_notification
WHERE notification_receiver_id = '".$receiver_id."'
AND read_notification = 'no'
";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
return $row["total"];
}
}
function Load_notification($connect, $receiver_id)
{
$query = "
SELECT * FROM tbl_notification
WHERE notification_receiver_id = '".$receiver_id."'
ORDER BY notification_id DESC
";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
$output = '';
if($total_row > 0)
{
foreach($result as $row)
{
$output .= '<li><a href="#">'.$row["notification_text"].'</a></li>';
}
}
return $output;
}
function Get_user_name($connect, $user_id)
{
$query = "
SELECT username FROM tbl_twitter_user
WHERE user_id = '".$user_id."'
";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
return $row["username"];
}
}
function count_retweet($connect, $post_id)
{
$query = "
SELECT * FROM tbl_repost
WHERE post_id = '".$post_id."'
";
$statement = $connect->prepare($query);
$statement->execute();
return $statement->rowCount();
}
function count_comment($connect, $post_id)
{
$query = "
SELECT * FROM tbl_comment
WHERE post_id = '".$post_id."'
";
$statement = $connect->prepare($query);
$statement->execute();
return $statement->rowCount();
}
function make_follow_button($connect, $sender_id, $receiver_id)
{
$query = "
SELECT * FROM tbl_follow
WHERE sender_id = '".$sender_id."'
AND receiver_id = '".$receiver_id."'
";
$statement = $connect->prepare($query);
$statement->execute();
$total_row = $statement->rowCount();
$output = '';
if($total_row > 0)
{
$output = '<button type="button" name="follow_button" class="btn btn-warning action_button" data-action="unfollow" data-sender_id="'.$sender_id.'"> Following</button>';
}
else
{
$output = '<button type="button" name="follow_button" class="btn btn-info action_button" data-action="follow" data-sender_id="'.$sender_id.'"><i class="glyphicon glyphicon-plus"></i> Follow</button>';
}
return $output;
}
function count_total_post_like($connect, $post_id)
{
$query = "
SELECT * FROM tbl_like
WHERE post_id = '".$post_id."'
";
$statement = $connect->prepare($query);
$statement->execute();
return $statement->rowCount();
}
function Get_user_id($connect, $username)
{
$query = "
SELECT user_id FROM tbl_twitter_user
WHERE username = '".$username."'
";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
return $row["user_id"];
}
}
?>
register.php
For any dynamic web application, we have to first make register form. So, here also first we want to make user registration system. So, new user can register into system. So, for make any dynamic system, here we have make this register form. In this system, here we have validate username already exists or not. If username already exists then user cannot register into system. In this registration system we have also validate user password by re-entering password. So, this is basic validation, which we have use here for make registration system for Follow Unfollow system using PHP with Ajax jQuery Mysql and Bootstrap.
Once you have make registration system in Follow Unfollow application. After registration you have to make login page for authenticate user login details like username and password. Here password will be validate by using password_hash() method. Because at the time registration we have store password in hash format. If user has enter proper details, then his for validate user is login or not in whole system, we have store user details under $_SESSION variable.
If system is validated user information, and it is correct then page will be redirect to index.php page. From this page user can share his or her post. User can view his or her post along with post of follow user by login user. On index page user can view all user list with follow and unfollow button. Most of all operation of follow and unfollow system like post new post, comment on other user post, follow and unfollow other user, repost follow yser post will be done on this page. This page will be view to only login user.
This file is used for make dynamic menu, here user name will be display by using $_SESSION varibale. Here in this we have add two menu for go to profile page and logout page.
If user want to logout from dynamic follow unfollow application, so when user click on logout link then page will redirect to this page, and on this page all $_SESSION variable will be destroy using session_destroy() function.
This file is used for edit user profile details in follow unfollow application by using PHP. Here user not only edit their profile details like username, password, name and short bio but also user can change profile image by upload image file under images folder. This image and user name will be display to other user.
This file is used for perform all core operation of Insert Post, Fetch post data, fetch user data and make follow unfollow button in PHP Follow Unfollow system. This file will received request for all above operation.
This is our PHP Ajax Follow Unfollow System source code, If there is any new feature has been added then we will add updated source code under this post.
Notice: Array to string conversion in C:\xampp\htdocs\tutorial\Twitter Like Follow Unfollow System in PHP using Ajax jQuery\action.php on line 17 No Post Found
please, help, there's an error in the profile.php script, here are the errors it gives
Notice: Array to string conversion in C:\Users\USER\Desktop\XAMP only\htdocs\followt\profile.php on line 79
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\Users\USER\Desktop\XAMP only\htdocs\followt\profile.php on line 79
we have been complaining about this, please, admin help us fix this
Notice: Array to string conversion in C:\xampp\htdocs\tutorial\Twitter Like Follow Unfollow System in PHP using Ajax jQuery\action.php on line 17 No Post Found this is my problem what happend i do
SELECT * FROM tbl_samples_post LEFT JOIN tbl_twitter_user ON tbl_twitter_user.user_id = tbl_samples_post.user_id WHERE tbl_samples_post.user_id = '".$_SESSION["user_id"]."' GROUP BY tbl_samples_post.post_id ORDER BY post_id DESC";
WHERE tbl_samples_post.user_id = '".$_SESSION["user_id"]."'
Thanks for your tutorials, I would requesting you to add couple tutorials for image post and video post and profile system like Twitter all users can see your followers and folloing users
please make tutorial gallery system have albums ( create album, delete album, rename album, getting albums size ) and image ( upload image, delete image, change images album to another album, rename image, getting size image upload image image with progress bar, image view like your websites image view ) thank you for your tutorials.
the script is ladden with errors, it doesn't work, i';m having errors in my profile.php script, it would not allow profile update s at all, please can anyone help me out? please
please, help, there's an error in the profile.php script, here are the errors it gives
Notice: Array to string conversion in C:\Users\USER\Desktop\XAMP only\htdocs\followt\profile.php on line 79
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\Users\USER\Desktop\XAMP only\htdocs\followt\profile.php on line 79
we have been complaining about this, please, admin help us fix this
please, we've been begging help fix this my email is storyhub8@gmail.com
feel free to send ud the correct profile.php script
Thanks pls I need php code for students result check
ReplyDeleteEmail: raphaelugonna@gmail.com
good jop guys
ReplyDeletegood
ReplyDeleteTrending Now
ReplyDeleteNotice: Array to string conversion in C:\xampp\htdocs\tutorial\Twitter Like Follow Unfollow System in PHP using Ajax jQuery\action.php on line 17
No Post Found
please, help, there's an error in the profile.php script, here are the errors it gives
DeleteNotice: Array to string conversion in C:\Users\USER\Desktop\XAMP only\htdocs\followt\profile.php on line 79
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\Users\USER\Desktop\XAMP only\htdocs\followt\profile.php on line 79
we have been complaining about this, please, admin help us fix this
Trending Now
ReplyDeleteNotice: Array to string conversion in C:\xampp\htdocs\tutorial\Twitter Like Follow Unfollow System in PHP using Ajax jQuery\action.php on line 17
No Post Found this is my problem what happend i do
SELECT * FROM tbl_samples_post
ReplyDeleteLEFT JOIN tbl_twitter_user ON tbl_twitter_user.user_id = tbl_samples_post.user_id
WHERE tbl_samples_post.user_id = '".$_SESSION["user_id"]."'
GROUP BY tbl_samples_post.post_id
ORDER BY post_id DESC";
WHERE tbl_samples_post.user_id = '".$_SESSION["user_id"]."'
I am getting errors in this field
Demo doesn't work. It'll register me, but it won't log me in.
ReplyDeleteOh, okay. Nevermind. Login system works, just can't have spaces between first and last names. Thanks
ReplyDeletegood job!
ReplyDeleteperfect harika
ReplyDeleteThanks for your tutorials, I would requesting you to add couple tutorials for image post and video post and profile system like Twitter all users can see your followers and folloing users
ReplyDeletethanks sir this code is the best .you save me with the code.you is generious
ReplyDeletethe registration doesn't work
ReplyDeleteWarning: include(database_connection.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/followers/register.php on line 7
ReplyDeletethere is no file exist with this database_connection.php in your folder or if you already have made it then recheck your spellings
Please Update the downloading link
ReplyDeletethank you, please add image view like your website picture view
ReplyDeleteplease make tutorial gallery system have albums ( create album, delete album, rename album, getting albums size ) and image ( upload image, delete image, change images album to another album, rename image, getting size image upload image image with progress bar, image view like your websites image view ) thank you for your tutorials.
ReplyDeletethe script is ladden with errors, it doesn't work, i';m having errors in my profile.php script, it would not allow profile update s at all, please can anyone help me out? please
ReplyDeleteplease, help, there's an error in the profile.php script, here are the errors it gives
ReplyDeleteNotice: Array to string conversion in C:\Users\USER\Desktop\XAMP only\htdocs\followt\profile.php on line 79
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\Users\USER\Desktop\XAMP only\htdocs\followt\profile.php on line 79
we have been complaining about this, please, admin help us fix this
please, we've been begging help fix this
my email is storyhub8@gmail.com
feel free to send ud the correct profile.php script
what about repost option its not working
ReplyDeleteHas anyone been able to fix the issue on profile.php?
ReplyDeletehow to add pagination? please include this feature too. thank you.
ReplyDeleteCreate post delete option for users.
ReplyDeleteA big Thanks to you sir, its really helpful
ReplyDelete