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

Hello,

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
<?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);
		$this->index();
	}
	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';
		}
		$query->execute($params);
		for ($i = 0; $row = $query->fetch(); $i++) {
			$posts[] = array('id' => $row['id'], 'content' => $row['content']);
			}
		} catch (PDOException $e) {
			echo $e->getMessage();
		}
		$query->closeCursor();
		$db = null;
		require_once($template);
		}
	}
	$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:
Forbidden

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

Thanks for the help
prinLeAAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

systechadminConsultantCommented:
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
Ray PaseurCommented:
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
prinLeAAuthor Commented:
Hello,

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:

Forbidden

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.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Ray PaseurCommented:
OK, let's try this first.  Have a close look at this URL:
href="http://localhost/phpDatabaseFive/getUsefulness/post.php>"

Open in new window

It ends with a right-wicket (the "greater-than" sign).  Try removing that, so it ends with just .php instead of .php>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prinLeAAuthor Commented:
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
Ray PaseurCommented:
Thanks for the points and thanks for using E-E, ~Ray
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.