Online breaking news web application in php

Here is a basic outline of a online breaking news web application in PHP:

Database Design

PHP Code

// Check connection if (!$conn) { die("Connection failed: ". mysqli_connect_error()); }

// Get the latest news $query = "SELECT * FROM news ORDER BY date_published DESC LIMIT 10"; $result = mysqli_query($conn, $query);

// Display the news while ($row = mysqli_fetch_assoc($result)) { echo "

". $row['title']. "

"; echo "

". $row['description']. "

"; echo "

Category: ". $row['category']. "

"; echo "

Published: ". $row['date_published']. "

"; echo "

Author: ". $row['author']. "

"; echo "
"; }

// Close the connection mysqli_close($conn); ?>

* `add_news.php`: This will be the page where users can submit new news articles.
```php
<?php
// Connect to the database
$conn = mysqli_connect("localhost", "username", "password", "breaking_news");

// Check connection
if (!$conn) {
    die("Connection failed: ". mysqli_connect_error());
}

// Get the form data
$title = $_POST['title'];
$description = $_POST['description'];
$category = $_POST['category'];
$author = $_POST['author'];

// Insert the new news article into the database
$query = "INSERT INTO news (title, description, category, author) VALUES ('$title', '$description', '$category', '$author')";
mysqli_query($conn, $query);

// Close the connection
mysqli_close($conn);

// Redirect to the main page
header("Location: index.php");
?>

// Check connection if (!$conn) { die("Connection failed: ". mysqli_connect_error()); }

// Get the news ID from the URL $news_id = $_GET['id'];

// Get the news article from the database $query = "SELECT * FROM news WHERE id = '$news_id'"; $result = mysqli_query($conn, $query);

// Display the news article while ($row = mysqli_fetch_assoc($result)) { echo "

". $row['title']. "

"; echo "

". $row['description']. "

"; echo "

Category: ". $row['category']. "

"; echo "

Published: ". $row['date_published']. "

"; echo "

Author: ". $row['author']. "

"; echo "
"; }

// Get the comments for the news article $query = "SELECT * FROM comments WHERE news_id = '$news_id'"; $result = mysqli_query($conn, $query);

// Display the comments while ($row = mysqli_fetch_assoc($result)) { echo "

". $row['comment_text']. "

"; echo "

Author: ". $row['author']. "

"; echo "

Commented: ". $row['date_commented']. "

"; echo "
"; }

// Close the connection mysqli_close($conn); ?>

* `add_comment.php`: This will be the page where users can submit new comments for a news article.
```php
<?php
// Connect to the database
$conn = mysqli_connect("localhost", "username", "password", "breaking_news");

// Check connection
if (!$conn) {
    die("Connection failed: ". mysqli_connect_error());
}

// Get the form data
$news_id = $_POST['news_id'];
$comment_text = $_POST['comment_text'];
$author = $_POST['author'];

// Insert the new comment into the database
$query = "INSERT INTO comments (news_id, comment_text, author) VALUES ('$news_id', '$comment_text', '$author')";
mysqli_query($conn, $query);

// Close the connection
mysqli_close($conn);

// Redirect to the view news page
header("Location: view_news.php?id=$news_id");
?>

Front-end Code