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
https://forums.phpfreaks.com/topic/286705-volumetric-calculator-help/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.