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

prinLeA
prinLeA used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Gaurav SinghSolutions Architect

Commented:
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
Most Valuable Expert 2011
Top Expert 2016

Commented:
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

Author

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.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Most Valuable Expert 2011
Top Expert 2016
Commented:
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>

Author

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
Most Valuable Expert 2011
Top Expert 2016

Commented:
Thanks for the points and thanks for using E-E, ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial