I have this program it uses two files. One is the handler and the other is the actual page.
Here is the handler:
[php]<?php
if (get_magic_quotes_gpc())
{
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process))
{
foreach ($val as $k => $v)
{
unset($process[$key][$k]);
if (is_array($v))
{
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
}
else
{
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}
if (isset($_GET[‘addjoke’]))
{
include ‘form.html.php’;
exit();
}
try
{
$pdo = new PDO(‘mysql:host=localhost;dbname=lphp’, ‘root’,
‘’);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec(‘SET NAMES “utf8”’);
}
catch (PDOException $e)
{
$error = ‘Unable to connect to the database server.’;
include ‘error.html.php’;
exit();
}
if (isset($_POST[‘joketext’]))
{
try
{
$sql = ‘INSERT INTO joke SET
joketext = joketext,
jokedate = CURDATE()’;
$s = $pdo->prepare($sql);
$s->bindValue(’:joketext’, $_POST[‘joketext’]);
$s->execute();
}
catch (PDOException $e)
{
$error = ‘Error adding submitted joke: ’ . $e->getMessage();
include ‘error.html.php’;
exit();
}
header(‘Location: .’);
exit();
}
if (isset($_GET[‘deletejoke’]))
{
try
{
$sql = ‘DELETE FROM joke WHERE id = :id’;
$s = $pdo->prepare($sql);
$s->bindValue(’:id’, $_POST[‘id’]);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error deleting joke: ’ . $e->getMessage();
include ‘error.html.php’;
exit();
}
header(‘Location: .’);
exit();
}
try
{
$sql = ‘SELECT joke.id, LEFT(joketext, 20), name, email FROM joke INNER JOIN author ON authorid = author.id’;
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching jokes: ’ . $e->getMessage();
include ‘error.html.php’;
exit();
}
$jokes = array();
while ($row = $result->fetch())
{
$jokes[] = array(‘id’ => $row[‘id’], ‘text’ => $row[‘joketext’], ‘name’ => $row[‘name’], ‘email’ => $row[‘email’]);
}
include ‘jokes.html.php’;
[/php]
and here is the actual page:
[php]
Here are all the jokes in the database:
<?php foreach ($jokes as $joke): ?><?php endforeach; ?> [/php]<?php echo htmlspecialchars($joke['joketext'], ENT_QUOTES, 'UTF-8'); ?> (by <?php echo htmlspecialchars($joke['name'], ENT_QUOTES, 'UTF-8'); ?>)
I get the following notice on the page and I would really like to know why this index is undefined please:
Undefined index: joketext in C:\wamp\www\Netbeans\PHP Power\index.php on line 93
Any help is greatly appreciated