Build your own databse driven website using php and mysql 4th edition

Hello I am on page 148-149 and cant seem to get the page working at all. I have tried running it in IE and FF and still same result. I ahve checked the code several times and also copied the code from the pdf sample book and still no luck.

The page should come up with the list of jokes in the database and a delete button next to each joke.

Can someone help me on this


What error messages are you getting if any?

Just get internet explorer cannot display this webpage.

If I shut-down the Apache web server I get that error.

Obviously as the whole local database has been shutdown…

Thats not my problem tho all my other programs work within the book as in adding jokes just this one has got me stuck and I dont know why.

Add the following two lines to the very beginning of the script so that the beginning of the script you have:

ini_set('display_errors', 1);

then run the script again, if it throws up any errors, paste them here

Hey, I replicated your problem. It could have been a service failing to start.

Still nothing no errors…

Cant seem to work it out ive even typed the scripts out again and still nothing…

Very strange! Try downloading the code archive for the book and trying the version of the file provided there. I’ve sent you the download URL by private message.

ive done everything i can think of even tried it on a different computer and still nothing.

I dont understand…

Try deliberately giving the script the wrong password for the database. If the script is running then when given the wrong database password it should throw up the “unable to connect to the database error”.

I’m also having problems with running the deletejoke script, even when I use the downloaded version.

Try adding en echo to the script after the <? something like:

echo 'This is a test of the delete script';

That will verify that the script is at least running.

Are there any jokes left after you delete the selected joke?

If not you’ll get a couple of errors:

Notice: Undefined variable: jokes in C:\wamp\www\phpmysql4\chapter4\deletejoke\jokes.html.php on line 12

Warning: Invalid argument supplied for foreach() in C:\wamp\www\phpmysql4\chapter4\deletejoke\jokes.html.php on line [B]12

[/B]This is because the foreach() function is expecting to be given an array but all it receives is a empty variable.

Change the end of the index.php from:

while ($row = mysqli_fetch_array($result))
    $jokes[] = array('id' => $row['id'], 'text' => $row['joketext']);

include 'jokes.html.php';


while ($row = mysqli_fetch_array($result))
    $jokes[] = array('id' => $row['id'], 'text' => $row['joketext']);

include 'jokes.html.php';


I have used all my scripts I typed up on both my computers (Laptop & Desktop) and it works on my desktop but not on my laptop but all other scripts work on my laptop just this deletejoke one doesnt for some reason. Beats me.


Hi, I’m having exactly the same problem, and have gone through the same process as described above, and the “Delete Joke” code from the book just does not work. It causes the Apache server to get stuck and shut down, though every other script in the book has worked so far.
I’m worried about what this means in terms of getting a “real” project to work, because it seems as though the creation of the $jokes array is the problem, and if this is a necessary step that allows us to uniquely identify rows of data, then that seems like a pretty crucial function!
Is there any other way to achieve the same goal?

Hello I worked around it to run all my programs off my memory stick using XAMPP (

If you download that to a memory stick and run the setup then all should work.

You need to copy all the stuff out of your htdocs directory on your local drive to the htdocs on the memory stick it creates.

If you have any problems let me know


This workaround you used makes me think that maybe it’s a configuration setting, either in Apache or PHP? Something that has to do with how arrays or variables are handled, maybe? I’m such a beginner, I really have no idea. But if at all possible, I’d like to try to fix the problem, rather than try to run the programs from a memory stick (though I’ll do it, if that’s what it takes). It just makes me nervous, because I keep thinking, how’s it going to work on the actual production server?
Also, it’s hard to move forward in the book, because all subsequent codes build on the “faulty” code (or, at least the code that’s not working on my machine).

What (precise) version of Apache, MySQL and PHP were you using? If you’ve still got the combination installed, try commenting out blocks of code then the troublesome section can be narrowed down.

I just recently purchased this book and have come up with the same issue. Apache keeps crashing when running the delete script from chapter 4. My info:

Apache 2.2.14
PHP 5.2.12
MySQL 5.1.41

The part of the script causing the problem for me is:

while ($row = mysqli_fetch_array($result))
	$jokes[] = array('id' => $row['id'], 'text' => $row['joketext']);

This was verified by returning the while loop to the way it was prior to adding the delete script.

Any help greatly appreciated!

It seems like most of the people who have trouble with that page are using around that version of Apache. I wonder if there is a bug with apache in the current versions.