Django is a very powerful python framework for web development. It is used to create very powerful backend servers using python.
Run this command to create a django project on your pc in the specifeid directory.
django-admin startproject myapp
To start creating the django app, run this command after going into the project directory created in last step.
python manage.py startapp chat
To start the server, run this command in the parent directory where manage.py is saved.
python manage.py runserver
So, as I meantioned in my last post, I started to learn React few months back. So, in this post I am going to show you the web app that I created in react. I learnt the same from the tutorials but I modified the code to remove some bugs. The name of the Website is TextUtyls
In this website, you can come and paste a part of text then use some tools in the text, at last copy the text. I know its very easy, but we start learning things from an easy project. And definitely, if you are going to make this, you will definitely learn a lot of things.
You can get the complete code of the website Click here
So, I think that's it for this post. If you want to learn react follow the above playlist. See you in the next post.
How To Learn React Step by Step:
React JS is a very popular web framework. It is a free and open-source front-end JavaScript library for building user interfaces or UI components. React JS is maintained by Facebook. So, if you are a web developer, you should be aware that everythin gwe see on the web is just html, css and the functioning things are simply javascript. You must have worked with html and css to make simple websites or standalone pages. But, what if you are building a large commercial website with many pages. There are a lot things to know about web development and many compplexitie4s in doing them like routing without reloading the pages.
So, React makes things much more easier and developer friendly to handle. Thus for a modern UI developer, you should learn this. Not only for UI, React helps in making a complete web app structure. This is not just for React. There are other JS libraries also like Angular, that you can learn to create modern web apps. But, in this post, we are discussing about React JS
So, a few months back from the time I wrote this post, I started to learn react. I followed a YouTube playlist that helped me. And if you are going to learn react then you can also follow it. But this is only if you know hindi. To access the playlist, click here.
This playlist makes you learn react by making projects. Which is I suppose the best way to learn programming. Like if you ask me, I never follow any tutorials. I just come across an idea and start building it. Yeah, most of the time I get frustrated as my ideas don't work. But this is how programming is. You learn to deal with problems. *Also, this is not a promotional post.*
So, I think that's it for this post. If you want to learn react follow the above playlist. See you in the next post.
In this article you will learn How can you make your own Like and Dislike system. We are going to make the logic in Php.
So if you don't know, PHP was a popular language for making websites backend. Even the world's biggest social network, Facebook was built in Php. But today, Php is not used much. Even its importance is decreasing day by day and it's becoming dead.
So Why did I made this in Php? Well the answer is simple. I know Php. Infact Php is a good language. You can even imagine the popularity of Facebook, which was made in Php. And its not bad to learn Php because if you are able to make the logics in it, it is definitely going to help you in other languages. There's no minus point for learning Php.
So, you must have seen like dislike systems on various social networks like YouTube. So 2 months back I wanted to create my own blog and I created it! I started from scratch and designed everything of it one by one as the ideas hit me. You can even have a look at it. TheShiveshNetwork I created this site piece by piece and designed it. And yeah this was my first complete website. With login system and few inbuilt features.
Well I know this site contains many bugs but they can be fixed by giving some time to them. Also I am telling this because I am not a kind of person who will keep you in confusion. I am still learning to code. But I love to build things and this site is for that.
The blog was getting completed day by day. So, the thing that I needed after a few days for this blog was a rating system. Where users can like or dislike the blog. So I started searching for tutorials on google and youtube to find the perfect thing that I wanted. Because I told, this was my first website so I needed a reference to understand how things are going to work.
After visiting many places, I couldn't find anything that could completely satisfy what I was thinking. The codes online even had lot of bugs. But one plus point, I had got my idea to use the things needed for making it and bring those things together. So, I started.
First of all, I created a mysql table to store the rating of posts. The table structure is as
Firstly, make a Mysql table named "posts"
Download
Then, make a Mysql table named "rating_info"
Download
Next, I connected to the mysql database in php and started writing my logic.
Finally, this was the thing I created. I was highly satisfied wuth its working. And I guess this is the best and complete like dislike system tutorial on the web with a free code. Just download, modify and use it. No need to waste your time on which I wasted weeks :)
Note: I have also combined login , signup and user authentication check and provided in the code below.
// The code. Just copy from here. Replace "
// initializing variables
$username = "";
$email = "";
$user_id = "";
$errors = array();
$db = mysqli_connect('localhost', 'root', '', 'test');
if (isset($_POST['reg_user'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
// form validation: ensure that the form is correctly filled ...
// by adding (array_push()) corresponding error unto $errors array
if (empty($username)) { array_push($errors, "Username is required"); }
if (empty($email)) { array_push($errors, "Email is required"); }
if (empty($password_1)) { array_push($errors, "Password is required"); }
if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}
// first check the database to make sure
// a user does not already exist with the same username and/or email
$user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user) { // if user exists
if ($user['username'] === $username) {
array_push($errors, "Username already exists");
}
if ($user['email'] === $email) {
array_push($errors, "email already exists");
}
}
// Finally, register user if there are no errors in the form
if (count($errors) == 0) {
$password = md5($password_1);
$query = "INSERT INTO users (username, email, password)
VALUES('$username', '$email', '$password')";
mysqli_query($db, $query);
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: main.php');
}
}
// LOGIN USER
if (isset($_POST['login_user'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);
if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}
if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: main.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}
if (!$db) {
die("Error connecting to database: " . mysqli_connect_error($db));
exit();
}
if (isset($_SESSION['loggedin'])) {
$user_id = $_SESSION['username'];
}
if (isset($_SESSION['success'])) {
// if user clicks like or dislike button
if (isset($_POST['action'])) {
$post_id = $_POST['post_id'];
$action = $_POST['action'];
switch ($action) {
case 'like':
$sql="INSERT INTO rating_info VALUES ('$user_id', $post_id, 'like')";
$sql1 = "SELECT * FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='dislike'";
$result = mysqli_query($db, $sql1);
if (mysqli_num_rows($result) > 0) {
$sql = "UPDATE rating_info SET rating_action='like' WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='dislike'";
}
break;
case 'dislike':
$sql="INSERT INTO rating_info VALUES ('$user_id', $post_id, 'dislike')";
$sql1 = "SELECT * FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='like'";
$result = mysqli_query($db, $sql1);
if (mysqli_num_rows($result) > 0) {
$sql = "UPDATE rating_info SET rating_action='dislike' WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='like'";
}
break;
case 'unlike':
$sql="DELETE FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id";
break;
case 'undislike':
$sql="DELETE FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id";
break;
default:
break;
}
// execute query to effect changes in the database ...
mysqli_query($db, $sql);
echo getRating($post_id);
exit(0);
}
}
// Get total number of likes for a particular post
function getLikes($id)
{
global $db;
$sql = "SELECT COUNT(*) FROM rating_info
WHERE post_id = $id AND rating_action='like'";
$rs = mysqli_query($db, $sql);
$result = mysqli_fetch_array($rs);
return $result[0];
}
// Get total number of dislikes for a particular post
function getDislikes($id)
{
global $db;
$sql = "SELECT COUNT(*) FROM rating_info
WHERE post_id = $id AND rating_action='dislike'";
$rs = mysqli_query($db, $sql);
$result = mysqli_fetch_array($rs);
return $result[0];
}
// Get total number of likes and dislikes for a particular post
function getRating($id)
{
global $db;
$rating = array();
$likes_query = "SELECT COUNT(*) FROM rating_info WHERE post_id = $id AND rating_action='like'";
$dislikes_query = "SELECT COUNT(*) FROM rating_info
WHERE post_id = $id AND rating_action='dislike'";
$likes_rs = mysqli_query($db, $likes_query);
$dislikes_rs = mysqli_query($db, $dislikes_query);
$likes = mysqli_fetch_array($likes_rs);
$dislikes = mysqli_fetch_array($dislikes_rs);
$rating = [
'likes' => $likes[0],
'dislikes' => $dislikes[0]
];
return json_encode($rating);
}
// Check if user already likes post or not
function userLiked($post_id)
{
global $db;
global $user_id;
$sql = "SELECT * FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='like'";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
return true;
}else{
return false;
}
}
// Check if user already dislikes post or not
function userDisliked($post_id)
{
global $db;
global $user_id;
$sql = "SELECT * FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='dislike'";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
return true;
}else{
return false;
}
}
$sql = "SELECT * FROM posts";
$result = mysqli_query($db, $sql);
// fetch all posts from database
// return them as an associative array called $posts
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
?>
php tutorial - like dislike system
Hey there, Mr.Known here... This is the first post on this blog but not my first project. I started to code back in 2019, when I learnt basics of html, css and I should not say but I saw PHP...
# Dare not ask Why? Okay! :')
So basically, my story begins from ... Error 500
That was 26 July, 2021. I wanted to improve my front end development skills. So I decided to make something that would also help me in Javascript. Because seriously, I am worse at it! At the end, I sat on my computer and started looking for an idea. Suddenly, I don't know why but one line said by Mark Zuckerberg hit me on my mind. Mark has once said during his speech at Harvard, "Facebook was not the first thing that I built... I also built games, chat systems, study tools and music players. I’m not alone. JK Rowling got rejected 12 times before publishing Harry Potter. Even Beyonce had to make hundreds of songs to get Halo. The greatest successes come from having the freedom to fail."
Well I know that's very motivating line... But I am not talking about that!
Well, I know you got what I am talking about, but I need to explain this...
Did you notice, he said Music Players... Well, That's where the idea came from... Thank you Zuck! :)
So, first things first, I did what's every web dev's first step,
that is to create a index.html file... Then it all started... Firstly I created the basic structure of the website in html then added some css in it...
Then after I was satisfied with the design { Well, that saisfaction is temporary... }
I created script.js file and started with my javascript part for the project.
After a few google searches and a few video tutorials, I completed the player in 3 hours. Well, thanks to the gods of developers, w3schools, stackoverflow, geeksforgeeks, youtube, ...
Note:
But, you should keep in mind that there's no program made which doesn't have bugs.
The most important part of a programmers life is debugging of code. That's where we spend most time staring at our code looking for a silly error that we committed.
Finally, managing with my studies and taking out some time for debugging, I guess today I completed it...
Not today actually, I meant to say the day I uploaded this post. See on the top.
This is the final look of the music player:
If you want the code of the music player, then you are just one comment away...
Right now, I am not providing the code because i think as of now, no one other than me is reading this...
Please let me know in the comments below that you are reading this post...