Jump to content

Volumetric Calculator Help


GR1FF1N80

Recommended Posts

I was wondering if anyone can help.

 

I'm trying to create an online volumetric calc, based on the following formula

 

=SUM(((height+width)*2)+length)/100

 

I have created the form and the php code to create this.

 

 

<form name="calc" method="post">
<center><table width="248" border="1" class="tabledetails">
  <tr>
    <td colspan="2">Volumetric Calc</td>
    </tr>
  <tr>
    <td width="114">Length (in cm)</td>
    <td width="144"><center><input name="length" type="text" id="length" size="10" maxlength="10" /></center></td>
  </tr>
  <tr>
    <td>Width (in cm)</td>
    <td><center><input name="width" type="text" id="width" size="10" maxlength="10" /></center></td>
  </tr>
  <tr>
    <td>Height (in cm)</td>
    <td><center><input name="height" type="text" id="height" size="10" maxlength="10" /></center></td>
  </tr>
  <tr>
    <td> </td>
    <td><center>
      <input type="reset" name="Reset" value="Reset" /> 
      <input type="submit" name="Submit" value="Calc"></center></td>
  </tr>
</table>
</center>
</form>

<?
if($_POST['Submit']!=''){
    
$variable_a = $_POST['length'];
$variable_b = $_POST['width'];
$variable_c = $_POST['height'];

$result = ((($variable_c + $variable_b) * 2) + $variable_a) / 100;

echo "<center></br><h1>Length & Girth Combined is $result metres</br>Length = $variable_a cm </br>Width = $variable_b cm </br> Height = $variable_c cm</h1></br></br><h2>If the length and girth combined are greater than 3m then the parcel can not be sent internationally.</h2></center>";

}

?>

 

However, when I run this in the first instance and display the form, I receive the following message:-

 

Notice: Undefined index: Submit in xxxx on line 94 and the form is shown. As soon as you click on the calc button, this works absolutely fine, and echoes the information to the screen, as it should, and the message disappears

 

I'm just stumped why it displays the Undefined index: Submit  message, and how can I resolve this?

 

Regards

 

Dave

Link to comment
Share on other sites

Change

if($_POST['Submit']!=''){

to

if(isset($_POST['Submit'])){

The problem is PHP will report an undefined index if you use an key to an array that doesnt exist. The   Submit   index wont exist if you have not submitted the form. Once the form is submitted the notice will disappear because now the index is defined. Using isset on $_POST['Submit'] will eliminate the notice if the form has not been submitted.

Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.