COuld someone please help me with this code. It is from a tutorial from Sitepoint. It is a jokes database that lists all the jokes in the db, with links for deleting jokes next to each, and a link at the bottom for adding a new joke (which calls the form portion in the same page). Everything works fine except the deletiong. The error message I get is
" Error deleting the joke: Unknown column '$jokeid' in 'where clause' "
Please, help.
<html>
<head>
<title>The INternet Joke Database</title>
</head>
<body>
<?php
error_reporting(E_ALL);
$db="my_db";
if (isset($GET['addjoke'])): / If the user wants to add a joke /
?>
<form action="<?=$SERVER['PHP_SELF']?>" method="post">
<p>
Type your joke here:<br>
<textarea name="joketext" rows="10" cols="40" wrap>
</textarea>
<br>
<input type="submit" name="submitjoke" value="SUBMIT">
</p>
</form>
<?php
else:
/ Default Page display - Connect to database server /
$dbconnect = @mysql_connect('localhost', 'root', '');
if (!$dbconnect)
{
die( '<p>Unable to connect to the ' . 'database server at this time.</p>');
}
/ Select the Jokes database /
if (! @mysql_select_db($db, $dbconnect) )
{
die( '<p>Unable to locate the joke ' . 'database at this time.</p>');
}
/ If a joke has been submitted, add it to the database /
if (isset($POST['submitjoke']))
{
$joketext = $POST['joketext'];
$sql = "INSERT INTO Jokes SET JokeText='$joketext', JokeDate=NOW()";
if (@($sql))
{
echo('<p>Your joke has been added.</p>');
}
else
{
echo('<p>Error adding submitted joke: ' . mysql_error() . '</p>');
}
}
/ If a joke has been deleted remove it from the database. /
if (isset($GET['deletejoke']))
{
$jokeid = $GET['deletejoke'];
$sql = 'DELETE FROM Jokes WHERE id=$jokeid';
if (@($sql))
{
echo('<p>The joke has been deleted. </p>');
}
else
{
echo('<p>Error deleting the joke: ' . mysql_error() . '</p>');
}
}
echo('<p> Here are all the jokes in our database: </p>');
/ Request the ID and text of all the jokes /
$result = @('SELECT id, JokeText FROM Jokes');
if (!$result)
{
die('<p>Error performing query: ' . mysql_error() . '</p>');
}
/ Display the text of each joke in a paragraph with a "delete this joke" link next to each /
while ($row = mysql_fetch_array($result) )
{
$jokeid = $row['id'];
$joketext = $row['JokeText'];
echo('<p>' . $joketext . '<a href="' . $SERVER['PHP_SELF'] . '?deletejoke=' . $jokeid . '">' .
'Delete this Joke</a></p>');
}
/ When clicked, this link will load this page with the joke submission form displayed /
echo('<p><a href="' . $SERVER['PHP_SELF'] . '?addjoke=1">Add a Joke!</a></p>');
endif;
?>
</body>
</html>