Database driven website by Kevin Yank

This is my first post here so apologies if the format is kind of messed up, I’m reading Build your own database driven website using PHP and MySQL. Until chapter 8, I managed to get all of the exercises to work with XAMPP on Win7 using the exact source code from the reference section.

When I put admin, includes and jokes folder into test folder located in c:/xampp/htdocs, and go to http://localhost/test/jokes, I get this where the list of jokes should be.

Fatal error: Call to undefined function bbcodeout() in C:\\xampp\\htdocs\	est\\jokes\\jokes.html.php on line 18

I also get the same error when searching at http://localhost/test/admin/jokes/

Here is the code for jokes.html.php from chapter 8

<?php include_once $_SERVER['DOCUMENT_ROOT'] .
		'/includes/helpers.inc.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>List of Jokes</title>
		<meta http-equiv="content-type"
				content="text/html; charset=utf-8"/>
	</head>
	<body>
		<p><a href="?addjoke">Add your own joke</a></p>
		<p>Here are all the jokes in the database:</p>
		<?php foreach ($jokes as $joke): ?>
			<form action="?deletejoke" method="post">
				<blockquote>
					<p>
						<?php bbcodeout($joke['text']); ?>
						<input type="hidden" name="id" value="<?php
								echo $joke['id']; ?>"/>
						<input type="submit" value="Delete"/>
					</p>
				</blockquote>
			</form>
		<?php endforeach; ?>
	</body>
</html>

I haven’t a clue as to what I did wrong since every exercise has worked up to this point, obviously it has something to do with bbcodeout but I couldn’t find any reference to this problem online.

Help please?

I’m running XAMPP 2.5

Hi dcd018,

Well. if you are using the files from the code archive, then I hope it isn’t because the code is buggy! Checking the book’s errata page for known errors I don’t see anything about it.

So what is it? My first guess is the path and or file name is off. But, if things were working in chapter 7, then you must have had

<?php include_once $_SERVER['DOCUMENT_ROOT'] .
		'/includes/helpers.inc.php'; ?>

in the right place with the right spelling.

The helpers.inc.php file used in chapter 7 doesn’t have a
function bbcode2html($text)

Did you remember to upgrade it with the one for chapter 8?

Thanks Mittineague, helpers.inc.php is updated and it’s in includes folder

function bbcodeout($text)
{
	echo bbcode2html($text);
}

So <?php bbcodeout($joke[‘text’]); ?> in jokes.html.php should call function bbcodeout($text) from helpers.inc.php, or am I missing something?

Yes, it should be.

Maybe its a permissions issue?

What happens if you type the path to it in your browser address bar?

Here’s what I get when I go to http://localhost/test/jokes/jokes.html.php

Add your own joke

Here are all the jokes in the database:

Notice: Undefined variable: jokes in C:\\xampp\\htdocs\	est\\jokes\\jokes.html.php on line 14

Warning: Invalid argument supplied for foreach() in C:\\xampp\\htdocs\	est\\jokes\\jokes.html.php on line 14

I’m at a loss :mad: … uninstalling/reinstalling XAMPP see if that does it.

Its a coding thing rather than a XAMPP thing so dont uninstall it!
What value do you get if you echo the path?


echo $_SERVER['DOCUMENT_ROOT'] . '/includes/helpers.inc.php';

Check that the DOCUMENT_ROOT and paths are right.

That was it! I had an includes folder in root from chapter 7 and just figured the includes folder in test folder from chapter 8 was being used. I just forgot to switch out the root folders for includes.

Thanks!

Glad you got it sorted :tup: