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.
- PHP
- MYSQL DATABASE
- CONNECTION TO DATABASE
- HTACCES
- POST TABLE
- DISPLAY POST PAGE
- DISPLAY PAGE FOR THE POST ARTICLE
Let's begin with those requirements above.
Database Struture
- title ->(text)
- slug ->(string)->unique
- content ->(longtext)
- 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
David
Please I need the part of this... Thanks sir