├── Account.php ├── README.md ├── Tag.php ├── add.php ├── database └── blog.sql ├── db.php ├── delete.php ├── edit.php ├── header.php ├── image_upload_function.php ├── images ├── 2.jpg ├── b (1).png ├── man.png ├── node.png ├── react.png ├── service_img2.png ├── service_img4.png └── service_img4_2.png ├── index.php ├── login.php ├── logout.php ├── post.php ├── result.php ├── session.php └── view.php /Account.php: -------------------------------------------------------------------------------- 1 | db = $db; 9 | } 10 | 11 | public function login($username,$password){ 12 | $sql = "SELECT username,password FROM users WHERE username='$username'AND password='$password'"; 13 | $result = mysqli_query($this->db,$sql); 14 | if(mysqli_num_rows($result)>0){ 15 | $_SESSION['username'] = $_POST['username']; 16 | header("location:result.php"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Study-blog 2 | This is a Blog website made using PHP and Javascript. 3 | The Website follows CRUD Operations, also has a admin panel. 4 | 5 | The Blogger also has options to upload images , the website is also mobile friendly. 6 | 7 | It also has comment section for the blogs , where people can comment on the posts. The user can also add multiple tags to the post. 8 | 9 | The Website uses MySQL as the database with the backend. 10 | -------------------------------------------------------------------------------- /Tag.php: -------------------------------------------------------------------------------- 1 | db = $db; 7 | } 8 | 9 | public function getAllTags(){ 10 | $sql = "SELECT * FROM tags"; 11 | $result = mysqli_query($this->db,$sql); 12 | return $result; 13 | } 14 | 15 | public function getTags($slug){ 16 | $data = []; 17 | //$sql = "SELECT * FROM tags"; 18 | $sql = "SELECT * 19 | FROM posts 20 | INNER JOIN post_tags 21 | ON post_tags.post_id = posts.id 22 | INNER JOIN tags 23 | ON tags.id = post_tags.tag_id 24 | WHERE tags.tag='$slug'"; 25 | $result = mysqli_query($this->db,$sql); 26 | //return $result; 27 | //$result = mysqli_query($this->db,$sql); 28 | foreach($result as $res){ 29 | array_push($data, $res['tag']); 30 | } 31 | return $data; 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /add.php: -------------------------------------------------------------------------------- 1 | 4 | 7 | 10 | 13 | 16 | 20 | addPost($title,$description,uploadImage(),$data,$slug); 30 | if($record==True){ 31 | echo"
Post added Successfully!
"; 32 | } 33 | }else{ 34 | echo"
Every field is required
"; 35 | } 36 | } 37 | ?> 38 | 39 |
40 |
41 |
42 |
43 |
44 |
Add post
45 |
46 |
47 | 48 | 49 |
50 | 51 |
52 | 53 | 54 |
55 | 56 |
57 | 58 | 59 |
60 |
61 | 62 | getAllTags() as $tag){ ?> 63 | 64 | 65 |
66 | 67 |
68 | 69 |
70 |
71 |
72 |
73 | 74 |
75 |
76 | 77 |
78 | 79 | 86 | 87 | -------------------------------------------------------------------------------- /database/blog.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 5.0.2 3 | -- https://www.phpmyadmin.net/ 4 | -- 5 | -- Host: localhost 6 | -- Generation Time: Jun 05, 2020 at 11:56 AM 7 | -- Server version: 10.4.11-MariaDB 8 | -- PHP Version: 7.4.5 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | START TRANSACTION; 12 | SET time_zone = "+00:00"; 13 | 14 | 15 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 16 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 17 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 18 | /*!40101 SET NAMES utf8mb4 */; 19 | 20 | -- 21 | -- Database: `blog` 22 | -- 23 | 24 | -- -------------------------------------------------------- 25 | 26 | -- 27 | -- Table structure for table `posts` 28 | -- 29 | 30 | CREATE TABLE `posts` ( 31 | `id` int(11) NOT NULL, 32 | `title` varchar(200) NOT NULL, 33 | `description` text NOT NULL, 34 | `image` varchar(80) NOT NULL, 35 | `created_at` datetime NOT NULL, 36 | `slug` varchar(200) NOT NULL 37 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 38 | 39 | -- 40 | -- Dumping data for table `posts` 41 | -- 42 | 43 | INSERT INTO `posts` (`id`, `title`, `description`, `image`, `created_at`, `slug`) VALUES 44 | (13, 'Node Js a Awesome Language', '

Node.js is an open source, cross-platform runtime environment for developing server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux.

', 'node.png', '2020-06-05 00:00:00', 'Node-Js-a-Awesome-Language'), 45 | (14, 'React is a Frontend Library', '

React is a JavaScript library created for building fast and interactive user interfaces for web and mobile applications. It is an open-source, component-based, front-end library responsible only for the application’s view layer. In Model View Controller (MVC) architecture, the view layer is responsible for how the app looks and feels. React was created by Jordan Walke,  at Facebook. 

Let’s take a look at an Instagram webpage example, entirely built using React, to get a better understanding of how React works. As the illustration shows, React divides the UI into multiple components, which makes the code easier to debug. This way, each component has its property and function.

Easy creation of dynamic applications: React makes it easier to create dynamic web applications because it requires less coding and offers more functionality, as opposed to JavaScript, where coding often gets complex very quickly.

', 'react.png', '2020-06-05 00:00:00', 'React'), 46 | (15, 'Android a great thing to learn', '

Android is a powerful operating system and it supports a large number of applications in Smartphones. These applications are more comfortable and advanced for users. The hardware that supports android software is based on the ARM architecture platform. The android is an open-source operating system that means that it’s free and anyone can use it. The android has got millions of apps available that can help you manage your life one or another way and it is available to low cost in the market for that reason android is very popular.

', 'man.png', '2020-06-05 00:00:00', 'Android-a-great-thing-to-learn'), 47 | (16, 'Java is a Programming Language', '

Today the Java platform is a commonly used foundation for developing and delivering content on the web. According to Oracle, there are more than 9 million Java developers worldwide and more than 3 billion mobile phones run Java.

In 2014 one of the most significant changes to the Java language was launched with Java SE 8. Changes included additional functional programming features, parallel processing using streams and improved integration with JavaScript. The 20th anniversary of commercial Java was celebrated in 2015.

', 'service_img2.png', '2020-06-05 00:00:00', 'Java-is-a-Programming-Language'); 48 | 49 | -- -------------------------------------------------------- 50 | 51 | -- 52 | -- Table structure for table `post_tags` 53 | -- 54 | 55 | CREATE TABLE `post_tags` ( 56 | `tag_id` int(11) NOT NULL, 57 | `post_id` int(11) NOT NULL 58 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 59 | 60 | -- 61 | -- Dumping data for table `post_tags` 62 | -- 63 | 64 | INSERT INTO `post_tags` (`tag_id`, `post_id`) VALUES 65 | (1, 7), 66 | (2, 7), 67 | (1, 8), 68 | (2, 8), 69 | (4, 9), 70 | (2, 10), 71 | (2, 13), 72 | (1, 14), 73 | (4, 15), 74 | (5, 15), 75 | (5, 16); 76 | 77 | -- -------------------------------------------------------- 78 | 79 | -- 80 | -- Table structure for table `tags` 81 | -- 82 | 83 | CREATE TABLE `tags` ( 84 | `id` int(11) NOT NULL, 85 | `tag` varchar(60) NOT NULL 86 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 87 | 88 | -- 89 | -- Dumping data for table `tags` 90 | -- 91 | 92 | INSERT INTO `tags` (`id`, `tag`) VALUES 93 | (1, 'react'), 94 | (2, 'node.js'), 95 | (3, 'android'), 96 | (4, 'html'), 97 | (5, 'java'); 98 | 99 | -- -------------------------------------------------------- 100 | 101 | -- 102 | -- Table structure for table `users` 103 | -- 104 | 105 | CREATE TABLE `users` ( 106 | `id` int(11) NOT NULL, 107 | `name` varchar(60) NOT NULL, 108 | `username` varchar(60) NOT NULL, 109 | `password` varchar(60) NOT NULL 110 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 111 | 112 | -- 113 | -- Dumping data for table `users` 114 | -- 115 | 116 | INSERT INTO `users` (`id`, `name`, `username`, `password`) VALUES 117 | (2, 'Raghav', 'hello', '5d41402abc4b2a76b9719d911017c592'); 118 | 119 | -- 120 | -- Indexes for dumped tables 121 | -- 122 | 123 | -- 124 | -- Indexes for table `posts` 125 | -- 126 | ALTER TABLE `posts` 127 | ADD PRIMARY KEY (`id`); 128 | 129 | -- 130 | -- Indexes for table `tags` 131 | -- 132 | ALTER TABLE `tags` 133 | ADD PRIMARY KEY (`id`); 134 | 135 | -- 136 | -- Indexes for table `users` 137 | -- 138 | ALTER TABLE `users` 139 | ADD PRIMARY KEY (`id`); 140 | 141 | -- 142 | -- AUTO_INCREMENT for dumped tables 143 | -- 144 | 145 | -- 146 | -- AUTO_INCREMENT for table `posts` 147 | -- 148 | ALTER TABLE `posts` 149 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17; 150 | 151 | -- 152 | -- AUTO_INCREMENT for table `tags` 153 | -- 154 | ALTER TABLE `tags` 155 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6; 156 | 157 | -- 158 | -- AUTO_INCREMENT for table `users` 159 | -- 160 | ALTER TABLE `users` 161 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; 162 | COMMIT; 163 | 164 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 165 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 166 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 167 | -------------------------------------------------------------------------------- /db.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /delete.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | deletePostBySlug($_GET['slug']); 10 | header('Location:result.php'); 11 | ?> 12 | -------------------------------------------------------------------------------- /edit.php: -------------------------------------------------------------------------------- 1 | 4 | 7 | 10 | 13 | 17 | updatePost($_POST['title'],$_POST['description'],$_GET['slug']); 20 | if($result==true){ 21 | echo"
Post updated Successfully!
"; 22 | } 23 | } 24 | ?> 25 | 26 |
27 |
28 | getSinglePost($_GET['slug'])as $post){ ?> 29 |
30 |
31 |
32 |
Edit post
33 |
34 |
35 | 36 | 37 |
38 | 39 |
40 | 41 | 42 |
43 | 44 |
45 | 46 | 47 | 48 |
49 | 50 | 51 | 52 |
53 | 54 |
55 | 56 | 57 |
58 |
59 |
60 | 61 |
62 | 63 |
64 | 65 |
66 | 73 | 78 | -------------------------------------------------------------------------------- /header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PHP Assignment 1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /image_upload_function.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmakumaraditya/Study-blog/12a2237af4850a50cefc8e902a19759060af946c/images/2.jpg -------------------------------------------------------------------------------- /images/b (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmakumaraditya/Study-blog/12a2237af4850a50cefc8e902a19759060af946c/images/b (1).png -------------------------------------------------------------------------------- /images/man.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmakumaraditya/Study-blog/12a2237af4850a50cefc8e902a19759060af946c/images/man.png -------------------------------------------------------------------------------- /images/node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmakumaraditya/Study-blog/12a2237af4850a50cefc8e902a19759060af946c/images/node.png -------------------------------------------------------------------------------- /images/react.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmakumaraditya/Study-blog/12a2237af4850a50cefc8e902a19759060af946c/images/react.png -------------------------------------------------------------------------------- /images/service_img2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmakumaraditya/Study-blog/12a2237af4850a50cefc8e902a19759060af946c/images/service_img2.png -------------------------------------------------------------------------------- /images/service_img4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmakumaraditya/Study-blog/12a2237af4850a50cefc8e902a19759060af946c/images/service_img4.png -------------------------------------------------------------------------------- /images/service_img4_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmakumaraditya/Study-blog/12a2237af4850a50cefc8e902a19759060af946c/images/service_img4_2.png -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 6 | 10 | 11 |
12 |
13 |
14 | getPost() as $post) { ?> 15 |
16 |
17 | 18 |

19 | Author:Admin
20 | Created: 21 |

22 |
23 |
24 |

25 |
26 |
27 | 28 | 29 | 30 |
31 |

Browse by Tags

32 |

33 | getAllTags() as $tag){?> 35 | 38 | 39 | 40 | 41 |

42 | 43 |
44 |
45 |
46 |
47 | 48 | 49 | 60 | -------------------------------------------------------------------------------- /login.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | login($_POST['username'],md5($_POST['password'])); 10 | 11 | 12 | } 13 | 14 | ?> 15 | 16 | 17 |
18 |
19 |

Admin Login

20 |
21 |
22 | 23 | 24 |
25 |
26 | 27 | 28 |
29 |
30 | 31 |
32 | 33 |
34 |
35 |
36 | -------------------------------------------------------------------------------- /logout.php: -------------------------------------------------------------------------------- 1 | db = $db; 8 | } 9 | public function addPost($title,$description,$image,$date,$slug){ 10 | 11 | 12 | $sql = "INSERT INTO posts(title,description,image,created_at,slug)VALUES('$title','$description','$image','$date','$slug')"; 13 | $result = mysqli_query($this->db,$sql); 14 | 15 | if($result){ 16 | if($_POST['tags']){ 17 | $tags = $_POST['tags']; 18 | $lastInsertedId = mysqli_insert_id($this->db); 19 | foreach($tags as $tag){ 20 | $sql="INSERT INTO post_tags(post_id,tag_id)VALUES('$lastInsertedId',$tag)"; 21 | $result = mysqli_query($this->db,$sql); 22 | } 23 | } 24 | } 25 | return $result; 26 | } 27 | 28 | public function getPost(){ 29 | if(isset($_GET['tag'])){ 30 | $tag = $_GET['tag']; 31 | $sql = "SELECT * 32 | FROM posts 33 | INNER JOIN post_tags ON posts.id = post_tags.post_id 34 | INNER JOIN tags ON tags.id = post_tags.tag_id 35 | WHERE tags.tag='$tag'"; 36 | $result = mysqli_query($this->db,$sql); 37 | return $result; 38 | 39 | } 40 | $sql = "SELECT * from posts"; 41 | $result = mysqli_query($this->db, $sql); 42 | return $result; 43 | } 44 | 45 | public function updatePost($title,$description,$slug){ 46 | $newImage = $_FILES['image']['name']; 47 | if(!empty($newImage)){ 48 | $image = uploadImage(); 49 | $sql = "UPDATE posts SET title ='$title',description='$description',image = '$image' WHERE slug = '$slug'"; 50 | $result = mysqli_query($this->db,$sql); 51 | return $result; 52 | 53 | }else{ 54 | $sql = "UPDATE posts SET title ='$title',description='$description' WHERE slug = '$slug'"; 55 | $result = mysqli_query($this->db,$sql); 56 | return $result; 57 | } 58 | } 59 | 60 | public function deletePostBySlug($slug){ 61 | $sql = "DELETE FROM posts WHERE slug='$slug'"; 62 | $result = mysqli_query($this->db,$sql); 63 | return $result; 64 | } 65 | 66 | public function getSinglePost($slug){ 67 | $sql = "SELECT * FROM posts WHERE slug='$slug'"; 68 | $result = mysqli_query($this->db, $sql); 69 | return $result; 70 | } 71 | } 72 | 73 | ?> 74 | -------------------------------------------------------------------------------- /result.php: -------------------------------------------------------------------------------- 1 | 4 | 9 | 10 |
11 |

All Posts

12 | 13 | 14 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | getPost() as $post){ ?> 34 | 35 | 36 | 37 | 38 | 43 | 44 | 45 | 46 |
TitleDescriptionCreated atAction
39 | 40 | 41 | 42 |
47 |
48 | -------------------------------------------------------------------------------- /session.php: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /view.php: -------------------------------------------------------------------------------- 1 | 7 | 8 |
9 |
10 | getSinglePost($_GET['slug']) as $post){ ?> 11 |
12 | 13 |
14 |
15 |

16 |

17 |
18 | 19 |
20 |
21 | --------------------------------------------------------------------------------