Unidentified index error in a simple form

Posted on 16th Feb 2014 by admin

I have been trying to make an HTML form that is handled by a PHP script. So far my attempts to get it to work have proven fruitless.

I'm referencing the Visual Quickstart Guide for PHP to learn PHP, & I have since been referencing countless other websites & as far as I can tell, I shouldn't be getting any errors. I have written the code exactly the way it is in the book, yet when I enter values into the fields it returns a "Notice: Undefined index: title in /home/optionst/public_html/test.php on line 20" error message for all of the fields.

This is the code that I've written to handle the data in the form:
Quote<?php

ini_set ('display_errors', 1);
error_reporting (E_ALL | E_STRICT);

$title = $_POST['title'];
$name = $_POST['name'];
$response = $_POST['response'];
$comments = $_POST['comments'];

print "Thank you, $title $name for your comments.";
print "You stated that you found this response to be $response and added: $comments ";

?>
Other than that, the only other text in the file is the html doctype, header & body tags. Line 20 is <$title = $_POST['title'];>

This is my html form:
Quote<form method="post" action="test.php">
<p>Name: <select name="title">
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
</select>
<input type="text" name="name" size="20" /></p>

<p>Email Address: <input type="text" name="email" size="20" /></p>

<p>Reponse: This is ...
<select name="response">
<option value="Excellent">Excellent</option>
<option value="Good">Good</option>
<option value="Boring">Boring</option>
</select>

<p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p>

<input type="submit" name="submit" value="Send My Feedback!" />

</form>

When I test the form, the "Notice: Undefined index: title in /home/optionst/public_html/test.php on line 20" appears for every field of the form. I have double checked that the values are all identical & that I put all the semi colons in. I can't think of anything else that would cause these errors.

Does anyone know why this would be happening?
Thanks

Other forums