Link to home
Avatar of prinLeA

asked on

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


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
Avatar of Systech Admin
Systech Admin
Flag of India image

it seems that the database is not having permission to the user kindly check the database if the mentioned user is having permissions on the database
What is the server operating system?  Is the header a "403 Forbidden" error?

If you're new to PHP and want to learn the language, this article can lead you to dependable learning resources, and more importantly, can help you avoid the many dangerous, wrong, and obsolete examples of PHP code that litter the internet.
Avatar of prinLeA



To sir Gaurav Singh yes sir the user has the full privilege I'm using root. To sir Ray Paseur the server OS is actually my local machine and I'm using Windows 8.1. It's a WAMP sir. The error says:


You don't have permission to access /phpdatabasefive/getUsefulness/post.php> on this server. and below it I can read this: Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80

Thanks for the help I really appreciate.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of prinLeA


Excellent! Very nice Expert-exchange is the best I hope it dominates the net where everyone find solution fast instead of wasting time with search engine
Thanks for the points and thanks for using E-E, ~Ray