Jump to content

Recommended Posts

I found this code which makes a BMI Calculator (Form) for me however when I click on submit it takes the user back to the index page ie. domain.com/index.php. How do I change it to go to, say, domain.com/calculator.php ?  :shy: The code 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 $

**/

 

 

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."<br />";

echo "Weigth, kg: ".$weightkg."<br />";

echo "Body Mass Index (BMI): ".$bmi."<br />";

echo "<strong>";

 

if ($bmi<16.5) {echo "Severely Underweight</strong><br />";}

if ($bmi>=16.5 && $bmi<=18.4) {echo "Underweight</strong><br />";}

if ($bmi>=18.5 && $bmi<=24.9) {echo "Normal</strong><br />";}

if ($bmi>=25 && $bmi<=29.9) {echo "Overweight</strong><br />";}

if ($bmi>=30 && $bmi<=34.9) {echo "Obese Class I</strong><br />";}

if ($bmi>=35 && $bmi<=39.9) {echo "Obese Class II</strong><br />";}

if ($bmi>=40) {echo "Obese Class III</strong><br />";}

echo "<br />";

 

}

 

 

$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 "<table style=\"width: 100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tr><td valign=\"top\">";

//echo "<h3>BMI Calculator</h3>";

echo "<form action=\"".$path."\" method=\"post\" >";

echo "<strong>Height</strong><br />";

echo "<select name=\"heightcm\" >";

for ($i=30; $i<=$n1; $i++){ echo "<option value=\"$i\">".$i." cm / ".floor($i / 30.48)." ft ".round(($i-(floor($i / 30.48)*30.48)) / 2.54, 1)." in </option>";}

echo "</select>";

echo "<br />";

echo "<strong>Weight</strong><br />";

echo "<select name=\"weightkg\" >";

for ($i=30; $i<=$n1; $i++){ echo "<option value=\"$i\">".$i." kg / ".round($i / 0.45359237,2)." pounds </option>";}

echo "</select>";

echo "<br />";

//echo "<input name=\"searchterm\" type=text size=\"27\" class=\"ns1\">";

echo "<br />";

echo "<input type=\"submit\" value=\"Calculate\" name=\"B1\">";

echo "</form><br />";

 

//DON'T REMOVE THIS LINK - DO NOT VIOLATE GNU/GPL LICENSE!!!

echo "<a href=\"http://nutritioncaloriecounter.com\">Nutrition Calorie Counter</a>";

//DON'T REMOVE THIS LINK - DO NOT VIOLATE GNU/GPL LICENSE!!!

echo "</td></tr></table>";

 

 

 

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/223446-linking/
Share on other sites

The easiest way is to name that file calculator.php, and everything works.

But you should be able to just remove the path and would execute same page.

 

This is your line

echo "<form action=\"".$path."\" method=\"post\" >";

 

So make it this

echo "<form action='' method=\"post\" >";

 

Or the complete with just the file as the post location value

<?php
$heightcm=$_POST["heightcm"];
$weightkg=$_POST["weightkg"];

if ($heightcm!="" && $weightkg!="") {

$heightm = $heightcm / 100;
$bmi=round($weightkg / ($heightm*$heightm),1);

echo "Heigth, m: ".$heightm."<br />";
echo "Weigth, kg: ".$weightkg."<br />";
echo "Body Mass Index (BMI): ".$bmi."<br />";
echo "<strong>";

if ($bmi<16.5) {echo "Severely Underweight</strong><br />";}
if ($bmi>=16.5 && $bmi<=18.4) {echo "Underweight</strong><br />";}
if ($bmi>=18.5 && $bmi<=24.9) {echo "Normal</strong><br />";}
if ($bmi>=25 && $bmi<=29.9) {echo "Overweight</strong><br />";}
if ($bmi>=30 && $bmi<=34.9) {echo "Obese Class I</strong><br />";}
if ($bmi>=35 && $bmi<=39.9) {echo "Obese Class II</strong><br />";}
if ($bmi>=40) {echo "Obese Class III</strong><br />";}
echo "<br />";

}


$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 "<table style=\"width: 100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tr><td valign=\"top\">";
//echo "<h3>BMI Calculator</h3>";


echo "<form action='calculator.php' method=\"post\" >";
//or even this
//echo "<form action='http://domain.com/calculator.php' method=\"post\" >";

echo "<strong>Height</strong><br />";
echo "<select name=\"heightcm\" >";
for ($i=30; $i<=$n1; $i++){ echo "<option value=\"$i\">".$i." cm / ".floor($i / 30.48)." ft ".round(($i-(floor($i / 30.48)*30.48)) / 2.54, 1)." in </option>";}
echo "</select>";
echo "<br />";
echo "<strong>Weight</strong><br />";
echo "<select name=\"weightkg\" >";
for ($i=30; $i<=$n1; $i++){ echo "<option value=\"$i\">".$i." kg / ".round($i / 0.45359237,2)." pounds </option>";}
echo "</select>";
echo "<br />";
//echo "<input name=\"searchterm\" type=text size=\"27\" class=\"ns1\">";
echo "<br />";
echo "<input type=\"submit\" value=\"Calculate\" name=\"B1\">";
echo "</form><br />";


//DON'T REMOVE THIS LINK - DO NOT VIOLATE GNU/GPL LICENSE!!!
echo "<a href=\"http://nutritioncaloriecounter.com\">Nutrition Calorie Counter</a>";
//DON'T REMOVE THIS LINK - DO NOT VIOLATE GNU/GPL LICENSE!!!
echo "</td></tr></table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/223446-linking/#findComment-1155072
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.