Undefined Index for $ _POST (question about the Nob!)

Possible duplicate:
PHP: "Note: Undefined variable" and "Notice: Undefined index"

I am just learning PHP and I keep getting Undefined index error. The book I am studying has an HTML form and a PHP page that processes the form using the following format:

<!-- The form fields are all set up something like this -->
<input type="text" id="howlong" name="howlong" /><br />

// The PHP starts with one line like this for each of the form fields in the HTML
$how_long = $_POST ['howlong'];

// And there is one line for each one like this to output the form data: 
echo ' and were gone for ' . $how_long . '<br />';

The example in which I work contains about 12 form fields.

What is strange is that not all variables throw this error, but I do not see a template in it.

I checked that all the HTML field names match the name of the PHP variable $ _POST that I entered, and I made sure that when I fill out the form and submit it, all the fields are filled with something. Interestingly, the completed code that can be downloaded for the book also causes this error.

, , , , noob:)

, , PHP 5.3.5 XAMPP 1.7.4 Windows 7 Home Premium.

+5
3

POST ...

, , , :

test.php:

<html>
  <body>
    <form method="POST" action="testProc.php">
      <input type="text" id="howlong" name="howlong" /><br/>
      <input type="submit" value="submit"/>
    </form>
  </body>
</html>

testProc.php:

<?php
if (isset($_POST)) {
  if (isset($_POST["howlong"])){
    $howlong = $_POST['howlong'];
    echo ' and were gone for ' . $howlong . '<br />';
  }
}
?>

, , , :

<html>
  <body>
    <form method="POST" action="testProc.php">
      <table>
        <tbody>
          <tr>
            <th>
              <label for="howlong">How long? :</label>
            </th>
            <td>
              <input type="text" id="howlong" name="howlong" />
            </td>
          </tr>
          <tr>
            <input type="submit" value="submit"/>
          </tr>
        </tbody>
      </table>
    </form>
  </body>
</html>

, ...

+6

, , $_POST, :

if(isset($_POST['send'])) {

"" -

+2

, ​​ isset().

In addition, not all HTML form elements will publish a value in all cases. A common example is a check box; check box unchecked box is not part of the data sent to the server. Therefore, the $ _POST element that you expect to install will not.

+1
source

All Articles