hi there,
I’ve encountered an http 500 server error while sending the values of the array jokes from index.php to jokes.html.php.
I’ve print_r the $sql statement and the jokes before sending it to jokes.html.php and it s fine the array has the DB results but when it comes to move on to the jokes.html.php I get the error and it s not very explicit.
here is my code for the index.php in www/admin/jokes/
if (isset($_GET['action']) && $_GET['action'] == 'search') {
//basic SELECT statement
$select = 'SELECT id, joketext ';
$from = 'FROM joke ';
$where = 'WHERE TRUE ';
$placeholders = array();
// If an author has been selected
if($_GET['author'] != '') {
$where .= ' AND authorid = :authorid';
$placeholders[':authorid'] = $_GET['author'];
}
//if a category has been selected
if($_GET['category'] != '') {
$from .= ' INNER JOIN jokecategory ON id = jokeid ';
$where .= ' AND categoryid = :categoryid';
$placeholders[':categoryid'] = $_GET['category'];
}
//if some text has been type in
if($_GET['text'] != '') {
$where .= 'AND joketext LIKE :joketext';
$placeholders[':joketext'] = '%' . $_GET['text'] . '%';
}
try {
$sql = $select . $from . $where;
$s = $pdo->prepare($sql);
$s->execute($placeholders);
}
catch (PDOException $e) {
$error = 'Error fecthing jokes: ';
$error .= $e->getMessage();
include TEMPLATES . 'error.html.php';
exit();
}
foreach($s as $row) {
$jokes = array( 'id' => $row['id'],
'text' => $row['joketext']);
}
include 'jokes.html.php';
exit();
}
and here is my code in the jokes.html.php in /www/admin/jokes/
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/helpers.inc.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Manage jokes: Search results</title>
</head>
<body>
<h1>Search results:</h1>
<?php if (isset($jokes)): ?>
<table>
<tr>
<th>Joke text</th><th>Options</th>
</tr>
<?php foreach($jokes as $joke):?>
<tr>
<td><?php htmlout($joke['text']);?></td>
<td>
<form action="?" method="post">
<div>
<input type="hidden" name="id" value="<?php htmlout($joke['id']?>" />
<input type="submit" name="action" value="Edit" />
<input type="submit" name="action" value="Delete" />
</div>
</form>
</td>
</tr>
<?php endforeach;?>
</table>
<?php endif;?>
<p><a href="?">New search</a></p>
<p><a href="..">Return to JMS home</a></p>
</body>
</html>
I’m a bit stuck there.
I’ve tried to echo “test”; in the first line of jokes.html.php (before the include_once) and I get the 500 error message.
but when I print_r($jokes); just before include ‘jokes.html.php’; I have the jokes in the array.
both files are in the same directory.
any lead on that please ?
cheers