We help IT Professionals succeed at work.
Get Started

You don't have permission to access /phpdatabasefive/getUsefulness/post.php> on this server

prinLeA asked
Last Modified: 2015-08-27

Need some help this is really a simple issue not really a problem but I'm a beginner there must be something in the setting that I'm missing or I don't know yet. Anyhow I got this from a book, I'm trying to learn PHP. Here is the code:

There are three files
1. post.php
2. list-posts.php
3. single-post.php

On post.php
class Posts {
	public $db = '';
	public function __construct() {
		$this->db = new PDO("mysql:host=localhost;dbname=testwopost", "root", "");
		$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	public function index() {
	$id = 0;
	$posts = array();
	$template = '';
	if (!empty($_GET['id'])) {
	$id = $_GET['id'];
	try {
		if (!empty($id)) {
		$query = $this->db->prepare("SELECT * FROM posts WHERE id = ?");
		$params = array($id);
		$template = 'single-post.php';
		} else {
		$query = $this->db->prepare("SELECT * FROM posts");
		$params = array();
		$template = 'list-posts.php';
		for ($i = 0; $row = $query->fetch(); $i++) {
			$posts[] = array('id' => $row['id'], 'content' => $row['content']);
		} catch (PDOException $e) {
			echo $e->getMessage();
		$db = null;
	$posts = new Posts();

Open in new window

On list-posts.php
<h1>List of Blog Posts</h1>
<?php foreach ($posts as $post): ?>
	<h3>Post #<?php echo htmlspecialchars($post['id']); ?></h3>
	<?php echo htmlspecialchars($post['content']); ?>
	<a href="http://localhost/phpDatabaseFive/getUsefulness/post.php?id=<?php echo htmlspecialchars($post['id']); ?>">Read More</a> <hr />
<?php endforeach; ?>

Open in new window

On single-post.php
<?php foreach($posts as $post): ?>
<h1>Post #<?php echo htmlspecialchars($post['id']); ?></h1>
<hr />
<?php echo htmlspecialchars($post['content']); ?>
<a href="http://localhost/phpDatabaseFive/getUsefulness/post.php>"> Backto Post List</a>
<?php endforeach; ?>

Open in new window

Everything seems working fine but on single-post.php when you click Backto Post List it will say:

You don't have permission to access /phpdatabasefive/getUsefulness/post.php> on this server.

Thanks for the help
Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE