Post Article On Site With Update And Delete Functions In PHP – Info PHP
Introduction
This article explains how to post articles on a site and if you want to update or delete an article then you can also do these operations in PHP. Let’s begin creating it. You will first need a table for storing article contents and then you will create a connection with your table.
This is your article table.

And the next step is your connection file for a connection with your database.
$hostname=“localhost”;
$username=“root”;
$password=“”;
$database_name=“demo”;
mysql_connect(“$hostname”, “$username”, “$password”)or die(“cannot connect”);
mysql_select_db(“$database_name”)or die(“cannot select DB”);
?>
Then you will create a “post.php” file and write code for posting the article and store the content into the table.
Example
ini_set(‘display_errors’,0);
include‘connect.php’;
if(isset($_POST[‘Submit‘])){
$title=$_POST[‘title’];
$descr=$_POST[‘descr’];
$keyword=$_POST[‘keyword’];
$content=$_POST[‘content’];
$category=$_POST[‘category’];
$query=“INSERT into article values(”,’$title’,’$descr’,’$keyword’,’$content’,”,’$category’)”;
$result=mysql_query($query)or die(mysql_error());
if($result){
echo “Successful Post your article…”;
echo “
“;
echo “View Your post artcile”;
}
else
{
echo “Error in your sql query please check again!”;
}}
?>
Output

And the next process is the article review and to create a file article.php and write the review code.
Example
include‘connect.php’;
$query=“SELECT * FROM article”;
$result=mysql_query($query);
?>
while($rows=mysql_fetch_array($result)){
?>
Title:
‘title’]; ?>
Description:
‘descr’]; ?>
Keyword:
‘keyword’]; ?>
Content:
‘content’]; ?>
}
?>
mysql_close();
?>
Output
Click on this link and view your article.

Your article review.

Then you will create am “Edit” and “Update” function and first an “Edit.php” file, such as the following.
Example
include‘connect.php’;
$id=$_GET[‘id’];
$query=“SELECT * FROM article WHERE id=’$id'”;
$result=mysql_query($query);
$rows=mysql_fetch_array($result);
?>
mysql_close();
?>
Click on the Edit link to edit your article as in the following:

Open your editor form and change your content here such as in the following:

![]()
If you are editing an article then given a reason why you are editing it, such as in the following:

And next is the “Update.php” file, such as in the following:
Example
ini_set(‘display_errors’,0);
include‘connect.php’;
//query with sql
if(!empty($_POST[‘reason‘])){
$query=“UPDATE article SET
title=‘”.mysql_real_escape_string($_POST[‘title‘]).”‘,
descr=‘”.mysql_real_escape_string($_POST[‘descr‘]).”‘,
keyword=‘”.mysql_real_escape_string($_POST[‘keyword‘]).”‘,
content=‘”.mysql_real_escape_string($_POST[‘content‘]).”‘, reason=‘”.mysql_real_escape_string($_POST[‘reason‘]).”‘ WHERE id=‘”.mysql_real_escape_string($_POST[‘id‘]).”‘”;
$result=mysql_query($query)or die(mysql_error());
if($result){
echo “Successful Update your record…”;
echo “
“;
echo “View Your updated data”;
}
else
{
echo “Error in your sql query please check again!”;
}}else{
echo ‘please type the reason’;
}
?>
Output

And finally you will create a “delete.php” file for deleting an article, such as in the following:
Example
ini_set(‘display_errors’,0);
include‘connect.php’;
$query=“DELETE FROM article WHERE id='”.$_GET[‘id’].“‘”;
$result= mysql_query($query)or die(mysql_error());
if($result){
echo “Successful delete your record…”;
echo “
“;
echo “View Your updated data”;
}
else
{
echo “Error in your sql query please check again!”;
}
?>
Output


Article Prepared by Ollala Corp
