BYO DB Driven Website using PHP & MySQL, Chapter 4, addjoke

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

Is php giving any errors? Try echoing the query and running it direct against MySQL

PHP does not give any errors. When I comment out everything below the line “$sql= etc”, add the echo to print it, and try again it will only print the command if using a get request. If I am using post I get the same form behaviour when submitting - it appears to refresh and simply represents an empty text box to me. In this case I left index.php with

if(isset($_REQUEST['joketext']))

and changed the form between post and get. As I say, when using get the form works and it behaves as expected but using post fails.