What is wrong here?

[php]

x = <?php echo "$number"; ?>

<?php // If the submit button has been clicked if (isset($_POST['multiply'])) { // Put the POSTed numbers into variables so we can easily work with them $firstnumber = $_POST['first_number']; $secondnumber = $_POST['second_number']; $number = $firstnumber * $secondnumber; } ?> [/php]

The above code does not display anything from the code: <?php echo "$number"; ?>

Why is that? What is wrong? Thank you in advance!

You need to move your php code where you calculate $number above the html form.

Just needs to be above the html.

hello Addeman, you have to did two changes 1. place your php code above the tag. but if you do not want than it's ok. 2. you are missing ; in action attribute of form. replace action="<?=$_SERVER['PHP_SELF']?>" with below code action="<?=$_SERVER['PHP_SELF'];?>"

other than this everything is fine.
SR

If he wants the variable to show up when he hits submit, then the php has to be on top of the page, or at least above the form.

Sponsor our Newsletter | Privacy Policy | Terms of Service