I am building the ‘addjoke’ project from pages 103 to 108 inclusive (4th Ed), and can’t make the bit to actually add jokes to the database work as it is written. When I run it, I can get to the index.php?addjoke form, but clicking ‘Add’ simply refreshes the form and does not add the joke to the database. I have been able to make it work by changing
if (isset($_POST['joketext']))
{
$joketext = mysqli_real_escape_string($link, $_POST['joketext']);
$sql = 'INSERT INTO joke SET
joketext="' . $joketext . '",
jokedate=CURDATE()';
if (!mysqli_query($link, $sql))
{
$error = 'Error adding submitted joke: ' . mysqli_error($link);
include'error.html.php';
exit();
}
header('Location: .');
exit();
}
to
if (isset($_REQUEST['joketext']))
{
$joketext = mysqli_real_escape_string($link, $_REQUEST['joketext']);
$sql = 'INSERT INTO joke SET
joketext="' . $joketext . '",
jokedate=CURDATE()';
if (!mysqli_query($link, $sql))
{
$error = 'Error adding submitted joke: ' . mysqli_error($link);
include'error.html.php';
exit();
}
header('Location: .');
exit();
}
and by changing the form submission method to ‘get’. Any thoughts on why the ‘post’ method isn’t working for me?
FYI I am on OS X running MySQL 5.1.48 and PHP 5.3.1