├── create.php ├── edit.php ├── index.php ├── logic.php └── view.php /create.php: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Blog using PHP & MySQL 17 | 18 | 19 | 20 |
21 |
22 | 23 | 24 | 25 |
26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /edit.php: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Blog using PHP & MySQL 17 | 18 | 19 | 20 |
21 | 22 |
23 | ' name="id"> 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Blog using PHP & MySQL 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 31 | 32 |
33 | + Create a new post 34 |
35 | 36 | 37 |
38 | 39 |
40 |
41 |
42 |
43 |

...

44 | Read More 45 |
46 |
47 |
48 | 49 |
50 | 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /logic.php: -------------------------------------------------------------------------------- 1 | Not able to establish Database Connection

"; 12 | } 13 | 14 | // Get data to display on index page 15 | $sql = "SELECT * FROM blog_data"; 16 | $query = mysqli_query($conn, $sql); 17 | 18 | // Create a new post 19 | if(isset($_REQUEST['new_post'])){ 20 | $title = $_REQUEST['title']; 21 | $content = $_REQUEST['content']; 22 | 23 | $sql = "INSERT INTO blog_data(title, content) VALUES('$title', '$content')"; 24 | mysqli_query($conn, $sql); 25 | 26 | echo $sql; 27 | 28 | header("Location: index.php?info=added"); 29 | exit(); 30 | } 31 | 32 | // Get post data based on id 33 | if(isset($_REQUEST['id'])){ 34 | $id = $_REQUEST['id']; 35 | $sql = "SELECT * FROM blog_data WHERE id = $id"; 36 | $query = mysqli_query($conn, $sql); 37 | } 38 | 39 | // Delete a post 40 | if(isset($_REQUEST['delete'])){ 41 | $id = $_REQUEST['id']; 42 | 43 | $sql = "DELETE FROM blog_data WHERE id = $id"; 44 | mysqli_query($conn, $sql); 45 | 46 | header("Location: index.php"); 47 | exit(); 48 | } 49 | 50 | // Update a post 51 | if(isset($_REQUEST['update'])){ 52 | $id = $_REQUEST['id']; 53 | $title = $_REQUEST['title']; 54 | $content = $_REQUEST['content']; 55 | 56 | $sql = "UPDATE blog_data SET title = '$title', content = '$content' WHERE id = $id"; 57 | mysqli_query($conn, $sql); 58 | 59 | header("Location: index.php"); 60 | exit(); 61 | } 62 | 63 | ?> 64 | -------------------------------------------------------------------------------- /view.php: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Blog using PHP & MySQL 17 | 18 | 19 | 20 |
21 | 22 | 23 |
24 |

25 | 26 |
27 | Edit 28 |
29 | ' name="id"> 30 | 31 |
32 |
33 | 34 |
35 |

36 | 37 | 38 | Go Home 39 |
40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | --------------------------------------------------------------------------------