Download online news portal website in php

Here is a basic outline of how to create a simple online news portal website using PHP:

Step 1: Plan the website structure

Step 2: Set up the database

Step 3: Create the front-end

Step 4: Create the back-end

Step 5: Implement user authentication

Step 6: Implement search functionality

Step 7: Implement pagination

Step 8: Test and debug

Here is some sample PHP code to get you started:

<?php
// Connect to the database
$db = mysqli_connect("localhost", "username", "password", "database");

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

// Function to fetch articles
function fetch_articles() {
    $query = "SELECT * FROM articles";
    $result = mysqli_query($db, $query);
    $articles = array();
    while ($row = mysqli_fetch_assoc($result)) {
        $articles[] = $row;
    }
    return $articles;
}

// Function to display article listing
function display_article_listing() {
    $articles = fetch_articles();
    foreach ($articles as $article) {
        echo "<h2>". $article['title']. "</h2>";
        echo "<p>". $article['content']. "</p>";
        echo "<p>Category: ". $article['category']. "</p>";
        echo "<p>Author: ". $article['author']. "</p>";
        echo "<p><a href='article.php?id=". $article['id']. "'>Read more</a></p>";
    }
}

// Function to display article detail
function display_article_detail($id) {
    $query = "SELECT * FROM articles WHERE id = '$id'";
    $result = mysqli_query($db, $query);
    $article = mysqli_fetch_assoc($result);
    echo "<h2>". $article['title']. "</h2>";
    echo "<p>". $article['content']. "</p>";
    echo "<p>Category: ". $article['category']. "</p>";
    echo "<p>Author: ". $article['author']. "</p>";
    echo "<p><a href='comment.php?id=". $article['id']. "'>Leave a comment</a></p>";
}

// Function to submit article
function submit_article() {
    if (isset($_POST['title']) && isset($_POST['content']) && isset($_POST['category'])) {
        $title = $_POST['title'];
        $content = $_POST['content'];
        $category = $_POST['category'];
        $query = "INSERT INTO articles (title, content, category) VALUES ('$title', '$content', '$category')";
        mysqli_query($db, $query);
        header("Location: index.php");
        exit;
    }
}

// Function to edit article
function edit_article($id) {
    if (isset($_POST['title']) && isset($_POST['content'])) {
        $title = $_POST['title'];
        $content = $_POST['content'];
        $query = "UPDATE articles SET title = '$title', content = '$content' WHERE id = '$id'";
        mysqli_query($db, $query);
        header("Location: index.php");
        exit;
    }
}

// Function to delete article
function delete_article($id) {
    $query = "DELETE FROM articles WHERE id = '$id'";
    mysqli_query($db, $query);
    header("Location: index.php");
    exit;
}

// Function to submit comment
function submit_comment($id) {
    if (isset($_POST['comment'])) {
        $comment = $_POST['comment'];
        $query = "INSERT INTO comments (article_id, comment) VALUES ('$id', '$comment')";
        mysqli_query($db, $query);
        header("Location: article.php?id=". $id);
        exit;
    }
}

// Function to edit comment
function edit_comment($id) {
    if (isset($_POST['comment'])) {
        $comment = $_POST['comment'];
        $query = "UPDATE comments SET comment = '$comment' WHERE id = '$id'";
        mysqli_query($db, $query);
        header("Location: article.php?id=". $id);
        exit;
    }
}

// Function to delete comment
function delete_comment($id) {
    $query = "DELETE FROM comments WHERE id = '$id'";
    mysqli_query($db, $query);
    header("Location: article.php?id=". $id);
    exit;
}

// Display the article listing
display_article_listing();

// Display the article detail
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    display_article_detail($id);
}

// Submit article
if (isset($_POST['submit'])) {
    submit_article();
}

// Edit article
if (isset($_GET['edit'])) {
    $id = $_GET['edit'];
    edit_article($id);
}

// Delete article
if (isset($_GET['delete'])) {
    $id = $_GET['delete'];
    delete_article($id);
}

// Submit comment
if (isset($_POST['submit_comment'])) {
    $id = $_GET['id'];
    submit_comment($id);
}

// Edit comment
if (isset($_GET['edit_comment'])) {
    $id = $_GET['edit_comment'];
    edit_comment($id);
}

// Delete comment
if (isset($_GET['delete_comment'])) {
    $id = $_GET['delete_comment'];
    delete_comment($id);
}

This is just a basic example to get you started. You will need to modify and expand this code to fit your specific needs. Additionally, you should ensure that you are using secure practices such as validating user input and using prepared statements to prevent SQL injection.