The previous example from this book in which I both output entries from a joke database and can add them in worked flawlessly. However when I added in this code:
if (isset($_GET[‘deletejoke’]))
{
$id = mysqli_real_escape_string($link, $_POST[‘id’]);
$sql = “DELETE FROM joke WHERE id=‘$id’”;
if (!mysqli_query($link, $sql))
{
$error = 'Error deleting joke: ’ . mysqli_error($link);
include ‘error.html.php’;
exit();
}
header('Location: .');
exit();
}
as well as update the while loop to store two columns in an array:
The index.php file doesn’t open in any browser. I’ve gone through all my files about 5 times, and there are no syntax errors, so barring any other issues, my only conclusion is that the author’s code must be incorrect. Has anyone had any issues with this, or know what the problem might be?
tag seems to be more capable of color-coding regardless of whether <?php is used or not.
```php
with <?php
```php
<?php
$message = 'Hello world!';
?>
<p><?php echo $message;?></p>
After some selective code commenting, the template page displays, and I have the problem narrowed down to the sql select statement in the script, which is
$result = mysqli_query($link, 'SELECT id, joketext FROM joke');
if (!$result)
{
$error = 'Error fetching jokes: ' . mysqli_error($link);
include 'error.html.php';
exit();
}
I found that if I took out the id, and just kept the SELECT statement fetching the joketext element from the database, the template displays, albeit not correctly, but its a step in the right direction.
$result = mysqli_query($link, 'SELECT joke.id, joke.joketext FROM joke');
I have had errors in the past which have been a result of not listing the field in full. Have you also tried SELECT * which would bring everything and you can pick out what you want?
I tried both methods, but unfortunately neither worked. I have a feeling that it’s a combination of selecting both elements from the database and the author’s while loop: