I am going through the book Build Your Database Driven Web Site. I am on chapter 5 and I am trying to get the jokes.html.php page to load and work. I am getting this error when I try to install a joke to the data base. Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\chapter5\jokes\jokes.html.php on line 12
Here is the code I am working with I just do not see a problem on line 12.
<!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 echo htmlspecialchars($joke['text'], ENT_QUOTES,
'UTF-8'); ?>
<input type="hidden" name="id" value="<?php
echo $joke['id']; ?>"/>
<input type="submit" value="Delete"/>
(by <a href="mailto:<?php
echo htmlspecialchars($joke['email'], ENT_QUOTES,
'UTF-8'); ?>"><?php
echo htmlspecialchars($joke['name'], ENT_QUOTES,
'UTF-8'); ?></a>)
</p>
</blockquote>
</form>
<?php endforeach; ?>
</body>
</html>
Thank you in advance for all help Codin.