OK lovely people, I've stripped this right back to highlight the problem.
Here is the code:
<?php
// If the form has been submitted, validate the entries and insert the message into the database
if (isset($_POST['submit']))
{
// pick up the values entered in the form
$sender_name = trim ($_POST['sender_name']);
$sender_email = trim ($_POST['sender_email']);
$comment = trim ($_POST['message_body']);
// check for blanks
$form_error_msg = "";
if ($sender_name == "") { $form_error_msg = "You must enter your name"; }
elseif ($sender_email == "") { $form_error_msg = "You must enter an email address"; }
elseif ($comment == "") { $form_error_msg = "You must enter a comment"; }
if ($form_error_msg == "")
{
// there is data the form and no error message so we can insert the comment in the database
// write_new_message ($sender_name, $sender_email, $comment);
// header ("Location: thanks.php");
}
else
{
// there is a form_error_msg to display i.e. the user has has entered something wrong
// strip any slashes added by PHP (if magic quotes is ON).
if (get_magic_quotes_gpc () == 1)
{
$sender_name = stripslashes ($_POST['sender_name']);
$sender_email = stripslashes ($_POST['sender_email']);
$comment = stripslashes ($_POST['comment']);
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Post a new comment</title>
</head>
<body onLoad="document.forms.form1.sender_name.focus()">
<p>Please leave a comment</p>
<p><?php echo $form_error_msg ?></p>
<form method="post" name="form1" action="newpost.php">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Your name:</td>
<td><input name="sender_name" type="text" value="<?php echo $sender_name?>"></td>
</tr>
<tr>
<td>Your email:</td>
<td><input name="sender_email" type="text" value="<?php echo $sender_email?>"></td>
</tr>
<tr>
<td nowrap class="formtag">Comment:</td>
<td><textarea name="comment" cols="41" rows="10" wrap="hard" class="form_field" value="<?php echo $comment?>"></textarea></td>
</tr>
<tr>
<td ></td>
<td><input name="submit" type="submit" class="form_button" id="submit" value="Submit Comment" /></td>
</tr>
</table>
</form>
</body>
</html>
If I just click submit, without filling anything in, I get an error message - so I conclude the page is reloading, $_POST is being set as I expect, and so on.
If I enter <br><br><br> into the Your Name field the browser redirects to the 'home' public_html directory, for example if this file is old_newbie.com/test/newcomment.php after entering the <br>s it redirects to old_newbie.com.
I've removed all PHP and HTML, commented other lines and left in relevant comments - I hope my error is clear to someone!