As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

PHP parsing and debugging

oniianoniian Registered User regular
edited June 2007 in Help / Advice Forum
I am reading "PHP Programming with MySQL" by Don Goesselin. It seems like a good read but...

Except it does not discuss parsing input from an HTML page to a PHP document.

This what I have written for the HTML page to submit the info:
<html>
<head><title>BMI</title></head>
<body>
<form action="BMI.php" method="get">
<form>
<br><b> BMI calculator: enter your weight and height</b></br>
<br>Weight in kilograms:
<input type="number" size="3" maxlength="3" name="weight"></br>
<br>Height in metters:
<input type="number" size="3" maxlength="3" name="height"></br>
<br> <input type="submit" value="submit"></br>
</form>
</body>
</html>

And this the PHP that is suppose to process the info:
<HTML>
<HEAD><TITLE> Receiving W and H </TITLE> </HEAD>
<BODY>
<?PHP

$BMI = $_get(weight) / ($_get(height) * $_get(height));
print "<BR> Your Body Mass Index is: $BMI";
?>
</BODY>
</HTML>

So what am I doing wrong here?

Edit: Also as the title suggests, are there any debuggers out there for PHP like there are for JAVA?

oniian on

Posts

  • Options
    JaninJanin Registered User regular
    edited June 2007
    PHP is case sensitive. You'll need to use something like this: $_GET["weight"]. Note the quotes - the code might work without them if you're running a very old or mis-configured version of PHP, but always be sure to use them.

    Janin on
    [SIGPIC][/SIGPIC]
  • Options
    Sharp101Sharp101 TorontoRegistered User regular
    edited June 2007
    I've only done some simple stuff myself.... but try
    $BMI = $_GET['weight'] / ($_GET['height'] * $_GET['height']);
    


    Also, its been a while.... are HTML forms referenced by ID? or name?

    I think I remember it being element by ID......

    Sharp101 on
  • Options
    CKyleCKyle Registered User regular
    edited June 2007
    I see a couple things that look odd. I don't think "number" is a valid option for the type attribute for one, but that is probably just being ignored and a text box is showing up as the default.

    Another things I see is $_get(weight). $_GET is an array, so you should use [] instead. Also, you give it strings for your inputs.

    Try $BMI = $_GET / ($_GET * $_GET);

    CKyle on
  • Options
    JaninJanin Registered User regular
    edited June 2007
    Sharp101 wrote: »
    Also, its been a while.... are HTML forms referenced by ID? or name?

    I think I remember it being element by ID......

    By name.

    Janin on
    [SIGPIC][/SIGPIC]
  • Options
    oniianoniian Registered User regular
    edited June 2007
    Hot Damn it worked, thanks guys.

    And for that second question I am taking it that there is no such thing as a debugger for PHP?
    CKyle wrote:
    Also, you give it strings for your inputs.

    You lost me there but I am assuming you are suggesting changing the type from "number" (it now reads "int") to "string"?

    oniian on
  • Options
    CKyleCKyle Registered User regular
    edited June 2007
    oniian wrote: »
    Hot Damn it worked, thanks guys.

    And for that second question I am taking it that there is no such thing as a debugger for PHP?
    CKyle wrote:
    Also, you give it strings for your inputs.

    You lost me there but I am assuming you are suggesting changing the type from "number" (it now reads "int") to "string"?

    Oh, sorry. I meant you use strings for the $_GET array's keys. So I would type $_GET. I should have been more clear.

    The inputs tags should have type="text".

    CKyle on
Sign In or Register to comment.