GR1FF1N80 Posted March 5, 2014 Share Posted March 5, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286705-volumetric-calculator-help/ Share on other sites More sharing options...
Yohanne Posted March 5, 2014 Share Posted March 5, 2014 <form name = "calc" method = "post" action = "<?php echo $_SERVER['PHP_SELF'];?>"> Quote Link to comment https://forums.phpfreaks.com/topic/286705-volumetric-calculator-help/#findComment-1471478 Share on other sites More sharing options...
ginerjm Posted March 5, 2014 Share Posted March 5, 2014 Not sure what the post from Jayson... was about. As for the error message - show us line 94 so that we may point you in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/286705-volumetric-calculator-help/#findComment-1471521 Share on other sites More sharing options...
Ch0cu3r Posted March 5, 2014 Share Posted March 5, 2014 (edited) 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 March 5, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286705-volumetric-calculator-help/#findComment-1471523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.