Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
Assalamu-Alaikum Everyone,
# News Site Project

I am Nirob Hasan And I'm a Web Developer by profession. With experience and expertise spanning around 7 years, in the Digital space.
This is a PHP-based news site project.

Good amount of experience in development of web applications using PHP, Frameworks, JavaScript Library’s, CMS, API’s, Reporting tools and Payment Gateways. Skilled in digital technology innovation's, brand building and all phases of the Web development lifecycle with an expert in translating business requirements into technical solutions and fanatical about quality, usability, security, and scalability. Dealing with and resolving problems and issues which arise.
## Description

Thank you.
This project is a simple news site developed using PHP. It allows users to view news articles, browse by category, search by name or description, view author post.

Youtube Link: https://youtube.com/nirobhasan
## Requirements

- PHP 8.1.2
- MySQL
- Web server (Apache, Nginx)

## Installation

1. Clone the repository to your local machine:

```bash
git clone "https://github.com/manchuriqbal/news_project_raw_file.git"
```

2. Import the database:

- Navigate to the `database` directory.
- [Download the `news_site.sql` file](https://raw.githubusercontent.com/manchuriqbal/news_project_raw_file/manchur/database/news_site.sql) from GitHub.
- Import the downloaded `news_site.sql` file into your MySQL/MariaDB database.

3. Configure the database connection:

- Open the `admin/config.php` file.
- Update the database connection details (hostname, username, password, database name) accordingly.

## Usage

1. Start your web server.

2. Open a web browser and navigate to the project directory.

3. You should see the homepage of the news site.
40 changes: 36 additions & 4 deletions admin/add-category.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php include "header.php"; ?>
<?php include "header.php";
if ($_SESSION['role'] == '0') {
header('location: post.php');
}
?>
<div id="admin-content">
<div class="container">
<div class="row">
Expand All @@ -7,16 +11,44 @@
</div>
<div class="col-md-offset-3 col-md-6">
<!-- Form Start -->
<form action="" method="POST" autocomplete="off">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST" autocomplete="off">
<div class="form-group">
<label>Category Name</label>
<input type="text" name="cat" class="form-control" placeholder="Category Name" required>
<input type="text" name="category_name" class="form-control" placeholder="Category Name" required>
</div>
<input type="submit" name="save" class="btn btn-primary" value="Save" required />
<input type="submit" name="submit" class="btn btn-primary" value="Save" required />
</form>
<!-- /Form End -->
</div>
</div>
</div>
</div>
<?php include "footer.php"; ?>


<?php

if (isset($_REQUEST['submit'])) {
include "config.php";

$category_name = mysqli_real_escape_string($connection, $_POST['category_name']);

$query = "SELECT category_name FROM category WHERE category_name='$category_name'";
$result = mysqli_query($connection, $query) or die("query_failed");

$count = mysqli_num_rows($result);
echo $count;
if ($count > 0) {
echo "this name already used. try another one.";
} else {
$query1 = "INSERT INTO category(category_name) VALUES ('$category_name')";
$result1 = mysqli_query($connection, $query1) or die("query_failed");
if ($result1) {
header("location: category.php");
}
}

}

?>

20 changes: 16 additions & 4 deletions admin/add-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,29 @@
</div>
<div class="col-md-offset-3 col-md-6">
<!-- Form -->
<form action="" method="POST" enctype="multipart/form-data">
<form action="save-post.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="post_title">Title</label>
<input type="text" name="post_title" class="form-control" autocomplete="off" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1"> Description</label>
<textarea name="postdesc" class="form-control" rows="5" required></textarea>
<textarea name="post_desc" class="form-control" rows="5" required></textarea>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Category</label>
<select name="category" class="form-control">
<option value="" selected> Select Category</option>
<option disabled selected> Select Category</option>
<?php
include "config.php";
$query = "SELECT * FROM category";
$result = mysqli_query($connection, $query) or die('category query failed!');
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value='{$row["category_id"]}' > {$row['category_name']}</option>";
}
}
?>
</select>
</div>
<div class="form-group">
Expand All @@ -33,4 +43,6 @@
</div>
</div>
</div>
<?php include "footer.php"; ?>
<?php include "footer.php";

?>
44 changes: 39 additions & 5 deletions admin/add-user.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php include "header.php"; ?>
<?php include "header.php";
if ($_SESSION['role'] == '0') {
header('location: post.php');
}
?>
<div id="admin-content">
<div class="container">
<div class="row">
Expand All @@ -7,7 +11,7 @@
</div>
<div class="col-md-offset-3 col-md-6">
<!-- Form Start -->
<form action="" method ="POST" autocomplete="off">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method ="POST" autocomplete="off">
<div class="form-group">
<label>First Name</label>
<input type="text" name="fname" class="form-control" placeholder="First Name" required>
Expand All @@ -18,7 +22,7 @@
</div>
<div class="form-group">
<label>User Name</label>
<input type="text" name="user" class="form-control" placeholder="Username" required>
<input type="text" name="username" class="form-control" placeholder="Username" required>
</div>

<div class="form-group">
Expand All @@ -28,15 +32,45 @@
<div class="form-group">
<label>User Role</label>
<select class="form-control" name="role" >
<option value="0">Normal User</option>
<option value="0">Editor</option>
<option value="1">Admin</option>
</select>
</div>
<input type="submit" name="save" class="btn btn-primary" value="Save" required />
<input type="submit" name="submit" class="btn btn-primary" value="Add" required />
</form>
<!-- Form End-->
</div>
</div>
</div>
</div>
<?php include "footer.php"; ?>


<?php

if (isset($_REQUEST['submit'])) {
include "config.php";

$first_name = mysqli_real_escape_string($connection, $_POST['fname']);
$last_name = mysqli_real_escape_string($connection, $_POST['lname']);
$username = mysqli_real_escape_string($connection, $_POST['username']);
$password = mysqli_real_escape_string($connection, md5($_POST['password']));
$role = mysqli_real_escape_string($connection, $_POST['role']);

$query = "SELECT username FROM user WHERE username='$username'";
$result = mysqli_query($connection, $query) or die("query_failed");

$count = mysqli_num_rows($result);
if ($count > 0) {
echo "this username already used. try another one.";
} else {
$query1 = "INSERT INTO user(fname, lname, username, password, role) VALUES ('$first_name','$last_name','$username','$password','$role')";
$result1 = mysqli_query($connection, $query1) or die("query_failed");
if ($result1) {
header("location: users.php");
}
}

}

?>
117 changes: 71 additions & 46 deletions admin/category.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php include "header.php"; ?>
<?php include "header.php";
if ($_SESSION['role'] == '0') {
header('location: post.php');
}
?>
<div id="admin-content">
<div class="container">
<div class="row">
Expand All @@ -9,6 +13,27 @@
<a class="add-new" href="add-category.php">add category</a>
</div>
<div class="col-md-12">

<?php
include "config.php";
$limit = 3;

if (isset($_GET['page'])) {
$page_number = $_GET['page'];
} else {
$page_number = 1;
}

$offset = ($page_number - 1) * $limit;


$query = "SELECT * FROM category ORDER BY category_id DESC LIMIT {$offset}, {$limit} ";
$result = mysqli_query($connection, $query) or die('Query Field');
$count = mysqli_num_rows($result);

if ($count > 0) {

?>
<table class="content-table">
<thead>
<th>S.No.</th>
Expand All @@ -18,55 +43,55 @@
<th>Delete</th>
</thead>
<tbody>
<?php
$serial_no = ($page_number - 1) * $limit + 1;
while ($row = mysqli_fetch_assoc($result)) {

?>
<tr>
<td class='id'>1</td>
<td>Html</td>
<td>5</td>
<td class='edit'><a href='update-category.php'><i class='fa fa-edit'></i></a></td>
<td class='delete'><a href='delete-category.php'><i class='fa fa-trash-o'></i></a></td>
</tr>
<tr>
<td class='id'>2</td>
<td>Css</td>
<td>15</td>
<td class='edit'><a href='update-category.php'><i class='fa fa-edit'></i></a></td>
<td class='delete'><a href='delete-category.php'><i class='fa fa-trash-o'></i></a></td>
</tr>
<tr>
<td class='id'>3</td>
<td>Java</td>
<td>8</td>
<td class='edit'><a href='update-category.php'><i class='fa fa-edit'></i></a></td>
<td class='delete'><a href='delete-category.php'><i class='fa fa-trash-o'></i></a></td>
</tr>
<tr>
<td class='id'>4</td>
<td>Php</td>
<td>11</td>
<td class='edit'><a href='update-category.php'><i class='fa fa-edit'></i></a></td>
<td class='delete'><a href='delete-category.php'><i class='fa fa-trash-o'></i></a></td>
</tr>
<tr>
<td class='id'>5</td>
<td>Python</td>
<td>13</td>
<td class='edit'><a href='update-category.php'><i class='fa fa-edit'></i></a></td>
<td class='delete'><a href='delete-category.php'><i class='fa fa-trash-o'></i></a></td>
</tr>
<tr>
<td class='id'>6</td>
<td>Scss</td>
<td>3</td>
<td class='edit'><a href='update-category.php'><i class='fa fa-edit'></i></a></td>
<td class='delete'><a href='delete-category.php'><i class='fa fa-trash-o'></i></a></td>
<td class='id'><?php echo $serial_no++ ?></td>
<td><?php echo $row['category_name'] ?></td>
<td><?php echo $row['post'] ?></td>
<td class='edit'><a href='update-category.php?id=<?php echo $row['category_id'] ?>'><i class='fa fa-edit'></i></a></td>
<td class='delete'><a onclick="return confirm('Are You Sure?')" href='delete-category.php?id=<?php echo $row['category_id'] ?>'><i class='fa fa-trash-o'></i></a></td>
</tr>
</tbody>

<?php } ?>

</table>
<ul class='pagination admin-pagination'>
<li class="active"><a>1</a></li>
<li><a>2</a></li>
<li><a>3</a></li>
</ul>

<?php } ?>

<?php
include "config.php";
$query2 = "SELECT * FROM category";
$result2 = mysqli_query($connection, $query2) or die("Failed.");


if (mysqli_num_rows($result2)) {
$total_user = mysqli_num_rows($result2);
$total_page = ceil($total_user / $limit);
echo '<ul class="pagination admin-pagination">';
if ($page_number > 1) {
echo '<li><a href="category.php?page=' . ($page_number - 1) . '">prev</a></li>';
}
for ($i = 1; $i <= $total_page; $i++) {
if ($i == $page_number) {
$active = "active";
} else {
$active = "";
}

echo '<li class="' . $active . '"><a href="category.php?page=' . $i . '">' . $i . '</a></li>';
}

if ($total_page > $page_number) {
echo '<li><a href="category.php?page=' . ($page_number + 1) . '">next</a></li>';
}
echo '</ul>';
}
?>
</div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions admin/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$connection = mysqli_connect('localhost', 'root', '', 'news_project_data') or die('Database not connected!'.mysqli_error);

?>
20 changes: 20 additions & 0 deletions admin/delete-category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "config.php";
if ($_SESSION['role'] == '0') {
header('location: post.php');
}
$category_id = $_REQUEST['id'];
$query = "DELETE FROM category WHERE category_id = '$category_id'";
$result = mysqli_query($connection, $query);

if ($result) {
header('location: category.php');
} else{
echo "can't delete this item";
}

mysqli_close()


?>
Loading