Creating a PHP Posting App Tutorial

Aug 24, 2024

Posting App Tutorial with PHP

Introduction

  • Presenter: Sandra
  • Purpose: To teach how to create a posting app using PHP.
  • The project combines learned skills with personal elements.
  • Features full CRUD functionality: Create, Read, Update, Delete.

Creating a Post

  1. Add Post:

    • Title: "Post 1"
    • Author: "Sanjay Raj"
    • Body: "Some content..."
    • Image URL
    • Posts can be viewed with a "Read More" option.
  2. Edit/Delete Functionality:

    • Posts can be edited or deleted.

Setting Up the Local Server

  • Using XAMPP as the local server.
  • Create a new folder in htdocs for the app files.

Database Setup

  1. Create Database:

    • Database Name: "host_app"
    • Create a new database and a table for the posts.
  2. Table Structure:

    • Columns: ID (auto-increment), Title (varchar), Author (varchar), Body (text), Created_at (timestamp).
    • Set ID as the primary key.
  3. Insert Data:

    • Sample data for posts:
      • Post 1: Title: "Post 1", Author: "Sanjay Raj"
      • Post 2: Title: "Post 2", Author: "Brad Travis"
    • Use the SQL INSERT command in phpMyAdmin to populate the table.

Connecting to the Database

  1. Configuration File:

    • Create config.php for database connection details
    • Define host, username, password, and database name.
  2. Connection Code:

    • Use mysqli_connect() to establish the connection.
    • Handle errors with appropriate error messages.

Fetching and Displaying Posts

  1. Create index.php:
    • Fetch posts from the database using SQL SELECT.
    • Use a foreach loop to iterate through posts and display them.
  2. Display Elements:
    • Each post will show title, a substring of the body, author, and created timestamp.
    • Include "Read More" link to view individual posts.

Conclusion

  • Completed setup for a basic posting app in PHP.
  • Next video will cover further functionalities, including creating new posts.
  • Reminder to check the links and post functionality.

Additional Notes

  • Ensure XAMPP is running.
  • Check for any errors in the setup process.