Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5969999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:18:41+00:00 2026-05-22T20:18:41+00:00

Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I am just learning

  • 0

Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”

I am just learning PHP and I keep getting an Undefined Index error. The book I’m learning from 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 I’m working with has about 12 form fields.

What’s odd is that not all of the variables throw this error, but I can’t see a pattern to it.

I’ve checked that all HTML fieldnames match up with the PHP $_POST variable name I entered, and I’ve made certain that when I fill out the form and submit it that all fields are filled in with something. Interestingly, the completed code that can be downloaded for the book also throws this error.

I realize this code may not reflect best practices, it’s from the first chapter of the book and obviously I am a noob 🙂

In case it makes a difference, I am using PHP 5.3.5 on XAMPP 1.7.4 with Windows 7 Home Premium.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:18:42+00:00Added an answer on May 22, 2026 at 8:18 pm

    Remember to set the method to POST on the form tag…

    heres the code i used to try yours, and it worked to me:

    in a file named 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>
    

    and in testProc.php:

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

    Just as an advise, to make display manipulation with stylesheets i recommend to put forms within a table, like this:

    <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>
    

    Hope you can use this…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php date compare I have a date that I take from the
Possible Duplicate: php headers already sent error I have attached my code which am
Possible Duplicate: Threads in PHP. I m getting a list of 20 urls. I
Possible Duplicate: Pass a PHP string to a Javascript variable (and escape newlines) I'm
Possible Duplicate: Using a javascript variable to set PHP variable I need to do
Possible Duplicate: PHP: How to generate a random, unique, alphanumeric string? i want to
Possible Duplicate: PHP DateTime::days returns trash? Ok, I don't get this... Could someone explain
Possible Duplicate: PHP Sort a multidimensional array by element containing date I have some
Possible Duplicate: php scandir --> search for files/directories I have a folder, inside this
Possible Duplicate: In PHP (>= 5.0), is passing by reference faster? I know the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.