Linking?

Hi everyone :smiley: I found this script to display a BMI form on my webpage and it works great but when you click on submit it goes back to index.php. is there anyway to make it so it stays on the same page?? The script is below:

<? /** * @package Module Body Mass Index Calculator for Joomla! 1.5 * @version $Id: mod_bodymassindexcalculator.php 599 2010-03-20 23:26:33Z you $ * @author Alex Barr * @copyright (C) 2010- Alex Barr * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html **/ defined( '_JEXEC' ) or die( 'Restricted access' ); $heightcm=$_POST["heightcm"]; $weightkg=$_POST["weightkg"]; if ($heightcm!="" && $weightkg!="") { $heightm = $heightcm / 100; $bmi=round($weightkg / ($heightm*$heightm),1); echo "Heigth, m: ".$heightm."
"; echo "Weigth, kg: ".$weightkg."
"; echo "Body Mass Index (BMI): ".$bmi."
"; echo ""; if ($bmi<16.5) {echo "Severely Underweight
";} if ($bmi>=16.5 && $bmi<=18.4) {echo "Underweight
";} if ($bmi>=18.5 && $bmi<=24.9) {echo "Normal
";} if ($bmi>=25 && $bmi<=29.9) {echo "Overweight
";} if ($bmi>=30 && $bmi<=34.9) {echo "Obese Class I
";} if ($bmi>=35 && $bmi<=39.9) {echo "Obese Class II
";} if ($bmi>=40) {echo "Obese Class III
";} echo "
"; } $domain = $_SERVER['HTTP_HOST']; $path = $_SERVER['SCRIPT_NAME']; $queryString = $_SERVER['QUERY_STRING']; $url = "http://" . $domain . $path; $url3 = "http://" . $domain . $_SERVER['REQUEST_URI']; $mystring1="?"; $s1=strpos($url3,$mystring1); if($s1==0) {$url2=$url3;} if($s1!=0) {$url2=substr($url3,0,$s1);} $path = $url2; //1 foot = 0.3048 meters //1 inch = 2.54 centimeters //1 pound = 0.45359237 kilograms $n1=230; echo "
"; //echo "

BMI Calculator

"; echo ""; echo "Height
"; echo ""; for ($i=30; $i<=$n1; $i++){ echo "".$i." cm / ".floor($i / 30.48)." ft ".round(($i-(floor($i / 30.48)*30.48)) / 2.54, 1)." in ";} echo ""; echo "
"; echo "Weight
"; echo ""; for ($i=30; $i<=$n1; $i++){ echo "".$i." kg / ".round($i / 0.45359237,2)." pounds ";} echo ""; echo "
"; //echo ""; echo "
"; echo ""; echo "
"; //DON'T REMOVE THIS LINK - DO NOT VIOLATE GNU/GPL LICENSE!!! echo "Nutrition Calorie Counter"; //DON'T REMOVE THIS LINK - DO NOT VIOLATE GNU/GPL LICENSE!!! echo "
"; ?>

$domain = $_SERVER['HTTP_HOST']; $path = $_SERVER['SCRIPT_NAME']; $queryString = $_SERVER['QUERY_STRING']; $url = "http://" . $domain . $path; $url3 = "http://" . $domain . $_SERVER['REQUEST_URI']; $mystring1="?"; $s1=strpos($url3,$mystring1); if($s1==0) {$url2=$url3;} if($s1!=0) {$url2=substr($url3,0,$s1);} $path = $url2;

This block of code really isn’t necessary as you can easily get the same out of the following:

$path = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

This way it is going to put the script’s name as the location and thus it will send the form information back to the script. And you don’t have to worry about all those lines of code. Hope this helps =D.

Sponsor our Newsletter | Privacy Policy | Terms of Service