I am trying to learn this but I am so not logical and I'm lost as all hell.

Anyway I'll just copy paste what I've already put on yahoo answers.

Can you help me figure this out this php?
So far this is what I have and I'm lost on what else to do. I have a test over it tomorrow so I really just want to kind of get the homework done and study my homework for the test. I'm not catching this stuff so well, I have one more assignment after this that I'm sure I'll be asking for help on. Anyway, This is my assignment---
Create a form that asks the user for the length and width of a rectangle. When the user presses "Submit" (or whatever you call it) the page should call a php page in the hmwk10 folder that will calculate the following:
* The perimeter of the rectangle (two times the length plus width)
* The area of the rectangle (length times the width)
* The length of the diagonal (square root of length times length plus width times width)

This is what I have in my php file:

<?php

if($_POST['form_submit'] == 'TRUE')
{

$width = 0;
$length = 0;
$perimeter = 0;
$area = 0;
$diag = 0;

if(is_numeric($_POST['width']))
{
$width = $_POST['width'];
}

if(is_numeric($_POST['length']))
{
$length = $_POST['length'];

echo $output;

?>

This is what I have in my html file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml…

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>PHP Sample</title>
</head>
<body>

<form action="process.php" method="post">
<div>
<input name="width" type="text" value="0"/>
<input name="length" type="text" value="0"/>
<input name="form_submit" type="hidden" value="TRUE"/>
<input type="submit" value="Calculate"/>
</div>
</form>

<hr />
<p><a href="http://validator.w3.org/check/refe… this page</a></p>
</body>
</html>

I'm confused. Someone helped with what I have so far and I'm still lost. Why am I putting zero after the width and lenght variables?

Also for the perimeter variable, shouldn't I have it say
$perimeter = (2 * $length) + $width;
and area
$area = $length * $width;
and for length of diaganoal
not sure how to do the length of the diagonal (square root of length times length plus width times width)

I really am lost on the logics of it all like what goes in php, what goes in html..bleh

you need to better explain what you want to do for us to help you with what you need

This is easy:

For the PHP script:

<html>
<head>
  <title>PHP Sample</title>
</head>
<body>
<?php
$height = $_POST["height"];
$width = $_POST["width"];
echo "Parimeter: " . 2*($height+$width) . "<br />
Area: " . $height*$width . "<br />
Diagonal: " . sqrt(($height*$height)+($width*$width));
?>
</body>
</html>

For the form:

<html>
<head>
  <title>PHP Sample</title>
</head>
<body>
  <form method="post">
  <table><!-- I just like to use tables to arrange content -->
    <tr>
      <td>Height: </td>
      <td><input name="height" type="text" /></td>
    </tr>
    <tr>
      <td>Width: </td>
      <td><input name="width" type="text" /></td>
    </tr>
    <tr>
      <input name="submit" type="submit" value="Calculate" />
    </tr>
  </table>
  </form>
</body>
</html>

Here is a file you can use for your project Learn form it there are a whole bunch of comments in this to tell you what I've done i used a little bit of code from the other Reply but improved with in one file that is in the attachment so grab it if ya want if you liked it and i helped you give me some Positive post points thanks and your welcome

Attachment Here ->
rect.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.