The links to the content work fine, however, when I go to a page (for example id=3) the links in the "righttop" section display as:
"Warning: Illegal string offset 'title' in C:\xampp\htdocs\blues\index.php on line 79"
and the links there don't work.
Basically links in the "topright" section work fine unless i'm on page with "id=" ; where I get the error messages.
Here's the code for my index.php so you can see what I mean by "topright"
<!DOCTYPE HTML>
<html lang = "en">
<?php
/*
* Include the necessary files
*/
include_once 'inc/functions.inc.php';
include_once 'inc/db.inc.php';
// Open a database connection
$db = new PDO(DB_INFO, DB_USER, DB_PASS);
/*
* Figure out what page is being requested (default is news)
* Perform basic sanitization on the variable as well
*/
if(isset($_GET['page']))
{
$page = htmlentities(strip_tags($_GET['page']));
}
else
{
$page = 'news';
}
// Determine if an entry ID was passed in the URL
$id = (isset($_GET['id'])) ? (int) $_GET['id'] : NULL;
// Load the entries
$e = retrieveEntries($db, $id);
// Get the fulldisp flag and remove it from the array
$fulldisp = array_pop($e);
// Sanitize the entry data
$e = sanitizeData($e);
?>
<head>
<title>The Blues Bar | Free Live Music Venue</title>
<meta charset = "UTF-8" />
<link rel = "stylesheet"
type = "text/css"
href = "style.css" />
</head>
<body>
<header>
Free live music 7 days a week | A selection of guest ales
</header>
<div id="wrapper">
<nav class="clearfix">
<a rel="external" href="index.php" class="button">Home</a><a rel="external" href="index.php?page=news" class="button">News</a><a rel="external" href="index.php?page=giglistings" class="button">Gig Listings</a><a rel="external" href="index.php?page=venue" class="button">The Venue</a><a rel="external" href="index.php?page=photos" class="button">Photos</a><a rel="external" href="index.php?page=contact" class="button">Contact</a>
<a id="twit" href="#"></a><a id="fb" href="#"></a>
</nav>
<div id="topcontent" class="clearfix">
<section id="lefttop">
<h1>Upcoming Gigs</h1><p>Sat 15th Sept - Jed ThomasMon 17th Sept - Jam Night</p>
</section>
<section id="righttop">
<h1>Recent News</h1><p>
<?php
foreach($e as $entrynav) {
?>
<p>
<a href="?page=news&id=<?php echo $entrynav['id'] ?>">
<?php echo $entrynav['title'] ?>
</a>
</p>
<?php
} // End the foreach loop
?>
</section>
</div>
<div id="core" class="clearfix">
<section id="left">
<div id="entries">
<?php
/*
* Very basic security measure to ensure that
* the page variable has been passed, enabling you to
* ward off very basic mischief using htmlentities()
*/
if(isset($_GET['page'])) {
$id = htmlentities($_GET['page']);
} else {
$page = NULL;
}
switch($page) {
case 'giglistings':
echo "
<h1> Gig Listings </h1>
<p> Here are the gig listings, under construction </p>";
break;
case 'news' :
// If the full display flag is set, show the entry
// If the full display flag is set, show the entry
if($fulldisp==1)
{
?>
<h2> <?php echo $e['title'] ?> </h2>
<p> <?php echo $e['created']?><?php echo $e['entry'] ?> </p>
<p class="backlink">
<a href="./">Back to Latest Entries</a>
</p>
<?php
} // End the if statement
// If the full display flag is 0, format linked entry titles
else
{
// Loop through each entry
foreach($e as $entry) {
?>
<p>
<a href="?page=news&id=<?php echo $entry['id'] ?>">
<?php echo $entry['title'] ?>
</a>
</p>
<?php
} // End the foreach loop
} // End the else
break;
case 'venue':
echo "
<h1> Venue </h1>
<p> This is the Blues Bar venue page, with all the information about the venue. </p>";
break;
case 'photos':
echo "
<h1> Photos </h1>
<p> Will be built at a later date when I have 100 years spare </p>";
break;
case 'contact':
echo "
<h1> Contact </h1>
<p> Contact us for a gig! </p>";
break;
/*
* Create a default page in case no variable is passed
*/
default:
echo "
<h1> Home </h1>
<p>
Lots of intresting indroductions to the blues bar etc. </p>";
break;
}
?>
</div>
</section>
<section id="right">
</section>
</div>
<footer>
<p>The Blues Bar</p>
</footer>
</div>
</body>
</html> ]
and here is my functions page: functions.inc.php
<?php
function retrieveEntries($db, $id=NULL)
{
/*
* If an entry ID was supplied, load the associated entry
*/
if(isset($id))
{
$sql = "SELECT title, entry , created
FROM news
WHERE id=?
LIMIT 1";
$stmt = $db->prepare($sql);
$stmt->execute(array($_GET['id']));
// Save the returned entry array
$e = $stmt->fetch();
// Set the fulldisp flag for a single entry
$fulldisp = 1;
}
/*
* If no entry ID was supplied, load all entry titles for the page
*/
else
{
$sql = "SELECT id, title, entry, created
FROM news
ORDER BY created DESC";
$stmt = $db->prepare($sql);
$stmt->execute(array($id));
$e = NULL; // Declare the variable to avoid errors
$result = $db->query($sql);
// Loop through returned results and store as an array
while($row = $stmt->fetch()) {
$e[] = $row;
}
// Set the fulldisp flag for multiple entries
$fulldisp = 0;
/*
* If no entries were returned, display a default
* message and set the fulldisp flag to display a
* single entry
*/
if(!isset($e))
{
$fulldisp = 1;
$e = array(
'title' => 'No Entries Yet',
'entry' => '<a href="/admin.php">Post an entry!</a>'
);
}
}
// Add the $fulldisp flag to the end of the array
array_push($e, $fulldisp);
return $e;
}
function sanitizeData($data)
{
// If $data is not an array, run strip_tags()
if(!is_array($data))
{
// Remove all tags except <a> tags
return strip_tags($data, "<a>");
}
// If $data is an array, process each element
else
{
// Call sanitizeData recursively for each array element
return array_map('sanitizeData', $data);
}
}
?>
I don't know how easy it will be for someone to know what's going on with my code and to help me but I thought there's no harm in asking.
Thanks for any help in advance












