├── README.md ├── blog_post_process.php ├── index.html ├── index.php ├── media ├── screenshot1.jpg ├── screenshot2.jpg └── screenshot3.jpg ├── scripts └── script.js └── styles └── style.css /README.md: -------------------------------------------------------------------------------- 1 | # A Simple Blog Using PHP And MySQL 2 | 3 | This simple blog application provides a user-friendly platform for bloggers to publish their posts online. It is built using PHP on the server-side and uses MySQL for storing blog posts. The application allows bloggers to write blog posts, add images and publish them on the blog. 4 | 5 | This application can be used as a starting point for developers who want to build a blog application using PHP and MySQL. 6 | 7 | 8 | ## Setup 9 | 10 | - Start the Apache and MySQL server from the XAMPP control panel. 11 | 12 | - Extract the downloaded git project folder in the htdocs folder(present in the XAMPP folder). Generally during installation the XAMPP is installed in the C: Drive of your computer. 13 | 14 | - A common file structure might looks like this: 15 | 16 | ``` 17 | C: 18 | |----XAMPP 19 | |----htdocs 20 | |----blog-using-php-mysql-main 21 | |----styles 22 | |----style.css 23 | |----media 24 | |----images 25 | |----scripts 26 | |----script.js 27 | |----blog_post_process.php 28 | |----index.html 29 | |----index.php 30 | |----README.md 31 | ``` 32 | 33 | - To create client's database go to: 34 | 35 | - Start by creating a new database from the left sidebar named as 'blog_db' with the default server connection collation settings. 36 | 37 | - After creating the database create a table named as 'blog_table' with 4 columns for id, topic_title, topic_date and topic_para. 38 | 39 | - The first column is 'id' which is an integer. Check the Auto Increment checkbox which will also make this field the primary key. 40 | 41 | - The next column will be for the 'Post Title' and we'll make this a text type field. 42 | 43 | - The next column is for the 'Date of the Created Post' which we'll make a text type field. 44 | 45 | - The next column will be of 'Post Paragraph' which we'll make a text type field. 46 | 47 | - After creating the database table you may test it by visiting this link in your browser: 48 | 49 | - On the `index.php` page all the created posts will be displayed. There is also a `Write a New Post` button on the bottom of the page from where you will be redirected to post creation page `index.html`. 50 | 51 | ## Features 52 | 53 | - On the home page `index.php` all the created posts are displayed. 54 | 55 | - Current date and time will be automatically inserted into the post during the time of post creation. 56 | 57 | - Major feature of user account creation and displaying dynamic content for each user is pending. 58 | 59 | - More features like post deletion, editing existing post and more will be addded soon. 60 | 61 | ## Screenshots 62 | 63 | ![blog-using-php-mysql](https://raw.githubusercontent.com/kshitizrohilla/blog-using-php-mysql/main/media/screenshot1.jpg) 64 | ![blog-using-php-mysql](https://raw.githubusercontent.com/kshitizrohilla/blog-using-php-mysql/main/media/screenshot2.jpg) 65 | ![blog-using-php-mysql](https://raw.githubusercontent.com/kshitizrohilla/blog-using-php-mysql/main/media/screenshot3.jpg) -------------------------------------------------------------------------------- /blog_post_process.php: -------------------------------------------------------------------------------- 1 | connect_error) die("Connection to database failed") . $conn->connect->error; 24 | 25 | $filename = "NONE"; 26 | 27 | if(isset($_FILES['uploadimage'])) 28 | { 29 | $GLOBALS['filename'] = $_FILES['uploadimage']['name']; 30 | 31 | $tempname = $_FILES['uploadimage']['tmp_name']; 32 | 33 | move_uploaded_file($tempname, "images/" . $GLOBALS['filename']); 34 | } 35 | 36 | $sql = "insert into blog_table (topic_title, topic_date, image_filename, topic_para) values ('" . $blogTitle . "', '" . $blogDate . "', '" . $filename . "', '" . $blogPara . "');"; 37 | 38 | if($conn->query($sql) === TRUE) 39 | { 40 | echo ""; 41 | } 42 | 43 | else 44 | { 45 | echo "Error Saving Post"; 46 | } 47 | 48 | $conn->close(); 49 | 50 | ?> 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Post Saved 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
71 | 72 |

Post Saved

73 | 74 |
Go to Home Page
75 | 76 |

77 | 78 | " . $blogTitle . "" ?> 79 |
80 | 81 |

82 | 83 |
84 | 85 |
86 | 87 | " . $blogPara . "" ?> 88 | 89 |

90 | 91 |
92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Blog Using PHP And MySQL 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | Blog | New Post 22 | 23 |
24 | 25 |
26 | 27 |
28 | 29 | 30 | 31 |
32 | 33 | Date: 34 | 35 | 36 | 37 |

38 | 39 | 40 | 41 |

42 | 43 | 44 | 45 |

46 | 47 | 48 | 49 |
50 | 51 |
52 | 53 |
Go to Home Page
54 | 55 |
56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Blog Using PHP And MySQL 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | Blog | All Posts 22 | 23 |
24 | 25 |
26 | 27 |
28 | 29 | connect_error) die("Connection Error" . $conn->connect_error); 42 | 43 | $sql = "select topic_title, topic_date, image_filename, topic_para from blog_table;"; 44 | 45 | $result = $conn->query($sql); 46 | 47 | if($result->num_rows > 0) 48 | { 49 | while($row = $result->fetch_assoc()) 50 | { 51 | echo "
"; 52 | 53 | echo "" . $row["topic_title"] . "
"; 54 | 55 | echo "" . $row["topic_date"] . "

"; 56 | 57 | echo "
"; 58 | 59 | echo "

" . $row["topic_para"] . "


"; 60 | 61 | echo "
"; 62 | } 63 | } 64 | 65 | else 66 | { 67 | echo "
No Blog Posts Found
"; 68 | 69 | // echo "
Write a New Post
"; 70 | } 71 | 72 | $conn->close(); 73 | 74 | ?> 75 | 76 |
77 | 78 |
Write a New Post

"; ?> 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /media/screenshot1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kshitizrohilla/blog-using-php-mysql/db659d28a60c3d5a538844137f7450877d51b74b/media/screenshot1.jpg -------------------------------------------------------------------------------- /media/screenshot2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kshitizrohilla/blog-using-php-mysql/db659d28a60c3d5a538844137f7450877d51b74b/media/screenshot2.jpg -------------------------------------------------------------------------------- /media/screenshot3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kshitizrohilla/blog-using-php-mysql/db659d28a60c3d5a538844137f7450877d51b74b/media/screenshot3.jpg -------------------------------------------------------------------------------- /scripts/script.js: -------------------------------------------------------------------------------- 1 | const d = new Date(); 2 | 3 | var DATE = String(d.getDate()) + '/' + String(d.getMonth()) + '/' + String(d.getFullYear()); 4 | 5 | var TIME = d.toLocaleString("en-US", 6 | 7 | { 8 | hour: "numeric", 9 | 10 | minute: "numeric", 11 | 12 | hour12: true 13 | } 14 | 15 | ); 16 | 17 | // console.log(DATE); 18 | 19 | // console.log(TIME); 20 | 21 | var dateTime = DATE + ', ' + TIME; 22 | 23 | document.getElementById("blogDate").value = dateTime; -------------------------------------------------------------------------------- /styles/style.css: -------------------------------------------------------------------------------- 1 | body 2 | { 3 | margin: 0; 4 | 5 | word-wrap: break-word; 6 | } 7 | 8 | .top-bar 9 | { 10 | background: #252525; 11 | 12 | color: #f5f5f5; 13 | 14 | margin: 0; 15 | 16 | text-align: center; 17 | 18 | padding: 10px; 19 | } 20 | 21 | #topBarTitle 22 | { 23 | font-family: "Segoe UI", sans-serif; 24 | 25 | text-align: center; 26 | 27 | margin: 0; 28 | 29 | font-size: 30px; 30 | } 31 | 32 | #dateLabel 33 | { 34 | font-family: "Segoe UI", sans-serif; 35 | 36 | font-weight: bold; 37 | } 38 | 39 | .writing-section 40 | { 41 | margin: 10px; 42 | } 43 | 44 | form 45 | { 46 | -webkit-tap-highlight-color: transparent; 47 | 48 | text-align: center; 49 | } 50 | 51 | #blogTitle 52 | { 53 | font-family: "Roboto", sans-serif; 54 | 55 | outline: none; 56 | 57 | border: 1.5px solid lightgrey; 58 | 59 | color: #333; 60 | 61 | font-size: 20px; 62 | 63 | width: 37.5%; 64 | 65 | margin-bottom: 5px; 66 | 67 | border-radius: 5px; 68 | 69 | padding: 5px 5px; 70 | } 71 | 72 | #blogPara 73 | { 74 | font-family: "Roboto", sans-serif; 75 | 76 | outline: none; 77 | 78 | border: 1.5px solid lightgrey; 79 | 80 | color: #333; 81 | 82 | resize: none; 83 | 84 | font-size: 20px; 85 | 86 | margin-top: 5px; 87 | 88 | border-radius: 5px; 89 | 90 | padding: 5px 5px; 91 | } 92 | 93 | #blogDate 94 | { 95 | border: none; 96 | 97 | outline: none; 98 | 99 | font-size: 1em; 100 | } 101 | 102 | #saveBtn 103 | { 104 | border: none; 105 | 106 | background: dodgerblue; 107 | 108 | color: #fff; 109 | 110 | font-size: 17.5px; 111 | 112 | padding: 5px 25px; 113 | 114 | border-radius: 5px; 115 | 116 | cursor: pointer; 117 | } 118 | 119 | .all-posts-container 120 | { 121 | /* 122 | margin-left: auto; 123 | 124 | margin-right: auto; */ 125 | 126 | font-family: "Roboto", sans-serif; 127 | 128 | display: flex; 129 | 130 | flex-direction: row; 131 | 132 | flex-wrap: wrap; 133 | 134 | align-items: center; 135 | 136 | justify-content: center; 137 | } 138 | 139 | .post-container 140 | { 141 | background: #d3d3d3; 142 | 143 | margin: 5px; 144 | 145 | width: 25%; 146 | 147 | height: 500px; 148 | 149 | border-radius: 15px; 150 | } 151 | 152 | #displayTitle 153 | { 154 | font-weight: bold; 155 | } 156 | 157 | #displayImage 158 | { 159 | width: 50%; 160 | 161 | height: auto; 162 | 163 | border-radius: 15px; 164 | } --------------------------------------------------------------------------------