Errors when loading text boxes

This weekend I decided to learn PHP, so I purchased the book Murach’s PHP and MySQL. XAMPP seems to have installed just fine. Some general example pages with php includes or calls to a database work without issue.

But as I’ve followed the tutorials, I’ve found some files that do not execute as expected. They are provided with the book, and I’m at a loss to understand where the problem is. As a novice, I don’t know if I should be looking at XAMPP, my version of PHP (which is 5.3.5), the database, or the code itself. Since it came with the book, I thought the code should be just fine.

One of these example files should yield a page that has empty text boxes, which will then be populated with data by the user. The problem is that when the page loads, the text boxes themselves are not empty. They have error codes within them. Followed by error codes outside of the boxes as well.

Here is the code for that page:

Future Value Calculator

Future Value Calculator

<?php if (!empty($error_message)) { ?>

<?php echo $error_message; ?>

<?php } // end if ?>
    <div id="data">
        <label>Investment Amount:</label>
        <input type="text" name="investment"
               value="<?php echo $investment; ?>"/><br />

        <label>Yearly Interest Rate:</label>
        <input type="text" name="interest_rate"
               value="<?php echo $interest_rate; ?>"/><br />

        <label>Number of Years:</label>
        <input type="text" name="years"
               value="<?php echo $years; ?>"/><br />
    </div>

    <div id="buttons">
        <label>&nbsp;</label>
        <input type="submit" value="Calculate"/><br />
    </div>

</form>
</div>

The error within the one of the text boxes is as follows:

<th align=‘left’ bgcolor=’#f57900’ colspan=

The error right after the box is:
Notice: Undefined variable: investment in C:\xampp\htdocs\book_apps\ch02_future_value\index.php on line 20 Call Stack #TimeMemoryFunctionLocation 10.0015334352{main}( )…\index.php:0 "/>

Interestingly, if you delete the errors within the text boxes and enter valid data, the file executes without error.

I’m not certain where to start with this. Does anybody have advice for me?

After much searching on the internet, I believe I found the issue:

[ul][li]Firstly, with good code, the variables should be given values of some sort.[/li]
[li]Secondly, these weren’t errors, but notices. I turned off notices in the php.ini file.[/li][/ul]

Sponsor our Newsletter | Privacy Policy | Terms of Service