Connect with us

How to create clean url in PHP (part 1)

kizinho

Published

on

Follow
NEWS: How to create clean url in PHP (part 1) [New  Developer] » Naijacrawl
Photo: Naijacrawl
site

Hi Folks, today share with you on how to write a clean URL in PHP, we all know while clean URL is very important for SEO for easy ranking of an article.

Will share my experience on how I was able to write a clean URL in PHP with you guys.

Requirements 

Will make use of PHP and my SQL no framework, we are using plain PHP, you can choose to do the same thing with PDO, MYSQLI depends on your codebase.

  1. PHP
  2. MYSQL DATABASE
  3. CONNECTION TO DATABASE
  4. HTACCES
  5. POST TABLE
  6. DISPLAY POST PAGE
  7. DISPLAY PAGE FOR THE POST ARTICLE


Let's begin with those requirements above.


Database Struture

  1. title ->(text)
  2. slug ->(string)->unique
  3. content ->(longtext)
  4. created_at ->(timestamp)

Database Connection

filename -> dbconection.php

$dbhost_name = "localhost";
$database = "naijacrawl"; // Change your database nae
$username = "root"// Your database user id 
$password = "";     // Your password//////// Do not Edit below /////////try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password, array(PDO::ATTR_PERSISTENT => true));
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "
"
; die(); }


Creating Post so that it can be inserted to the database

filename-> create_post.php

<html lang="en"><head><title> - Create Post title>
head><body><form method="post" action=""><input name="title"><input name="content"><button name="upload"> Upload button>
form>
body>html>


The upload page is now completed, it remains to write the PHP code that will process it.

Catch up to Part 11 on writing clean URL in PHP

Click Here To Comment


site


kizinho

I am a software developer, like meeting people and love blogging, that's why I developed naijacrawl because that's what I love doing.

Continue Reading
1 Comment

1 Comment

  1.   David

    Please I need the part of this... Thanks sir


Leave a Reply

Your email address will not be published. Required fields are marked *

PHP 7.3 Released

kizinho

Published

on

NEWS: PHP 7.3 Released [New  Developer] » Naijacrawl
Photo: Naijacrawl
Yesterday the PHP team released PHP 7.3.0 for general availability (GA) and marked the third feature update to PHP 7. You can download the latest version from the official PHP downloads page. You can also get all the nitty-gritty details about PHP 7.3 by reading the PHP 7 changelog on the official site. While today marks the day of the stable release, you will have to wait a bit longer for the migration guide, which should be available shortly. If you haven...
Continue Reading

Latest