We help IT Professionals succeed at work.

PHP Sytax error on Undefined Variable

Juan Velasquez
on
395 Views
Last Modified: 2013-11-21
Hello,

I am a rank beginner in PHP.  I've just started to teach myself PHP after many years in vba and some vb.net.  I am getting an undefined variable error when I first run the program.  From what I've read this is because the variables are not set when the application is started.  I'm trying to use the ISSET function to check the value of  variable.  If they are set, I would then like to execute the code. It looks like I'm still getting an error on the </html> tag.  It's some sort of syntax error but I'm not finding it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Future Value Calculator</title>
    <link rel="stylesheet" type="text/css" href="main.css"/>
</head>

<body>
    <div id="content">
    <h1>Future Value Calculator</h1>
    <?php if (!empty($error_message)) { ?>
        <p class="error"><?php echo $error_message; ?></p>
   
    <form action="display_results.php" method="post">

        <div id="data">
            <label>Investment Amount:</label>
            <input type="text" name="investment"

//this is where I put the isset function ----------------------------

            <?php if(isset($investment)) { ?>
                   value="<?php echo $investment; ?>"/><br />
            <?php } ?>


            <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>
</body>
</html>

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
You have an opening if block
<?php if (!empty($error_message)) { ?>

But you never close it

<?php }?>

p.s.
If you are just starting out then stick with the HTML5 doctype - no point using old doctypes
<!DOCTYPE html>

Author

Commented:
I went ahead and checked and it looks like I am closing it on line 25
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Oh I see.  I'm working from a sample file in the book I'm using.  I've rechecked the original sample file and that closing php tag is missing.
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
It's missing from the sample or just from your code?

Author

Commented:
It was missing from the sample

Author

Commented:
Thanks for the help.  I am also reading the links
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.