Jump to content

if statement does't seem to work


p3aul

Recommended Posts

Well, I didn't expect a response quite that fast! I was having trouble uploading a file in a previous request so I uploaded the file first instead of wasting a lot of time and tried to modify the post to provide the question! but this  forum software wouldn't let me HINT Get PHPbb!

 

Hi!

  I have uploaded a  webpage I'm working on. Everything seems to work fine, with no errors. Something is wrong with the logic though. I need one variable($db) to be larger than the other($wb) but the function I call to make sure of this isn't working right. It's called gthan and is the last function on the page. There is supposed to be an error msg displayed but instead the program goes ahead with the wrong data nd calculates and displays this data.

 

here is the sub routine:

if (isset($_POST['Submit'])) { //open brace MP  a
$db = $_POST["db"];
$wb = $_POST["wb"];
$pr = $_POST["pr"];
gthan($db, $wb);
calc( $db, $wb, $pr);

This is the subroutine:

function gthan($db, $wb){ //gthan opening brace e
if($db < $wb)
{ // if opening brace f
echo "<br>";
echo "&nbsp";
echo "&nbsp";
echo "<input type='text' size='38' name='gthan2' value='Drybulb must be greater than Wet Bulb'> ";
}// if closing brace f 
else{ return;}
} //gthan closing brace e
} //calc closing brace a

Can someone please help me with this?  :'(

Thank,

Paul

 

 

 

Link to comment
Share on other sites

Everything seems to work fine, with no errors.

 

Do you have errors turned on?  If not please put this at the top of your main script:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

Have you tried echoing the values to make sure they are correct?

 

 

Link to comment
Share on other sites

<?php

ini_set ("display_errors", "1");

error_reporting(E_ALL);

 

I put the ini_set script at the top of Main PHP code as you suggested and with the correct input, the output is correct, but when the wetbulb is > than the drybulb I get 144% humidity! which of course is incorrect! There was no display of any errors.

Paul :(

Link to comment
Share on other sites

I put the ini_set script at the top of Main PHP code as you suggested and with the correct input, the output is correct, but when the wetbulb is > than the drybulb I get 144% humidity! which of course is incorrect! There was no display of any errors.

 

If you actually get output then there's something wrong with your logic.  Let's see the calc function.

Link to comment
Share on other sites

Ok here is the calc function, but it works in all the code I've tried so far, just not with the wetbulb > than the drybulb. I'm just trying to idiot-proof the input.

 

Ok this is the code for the calulation written as a function:

 

function calc($db, $wb, $pr){ //opening brace calc b

if ( ! preg_match('/^\d+$/', $db) || ! preg_match('/^\d+$/', $wb) || ! preg_match('/^\d+$/', $pr)) 
{ // if opening brace c


echo "<br>";

echo "&nbsp";
echo "&nbsp";
echo "<input type='text' size='14' name='error' value='Numbers Only!'>";} //if closing brace c


else { //  else opening brace d

//Calculation Begins

$F = 6.112 * exp((17.67*$wb)/($wb+243.5));

$Ew = $F;


$H = 6.112 * exp((17.67*$db)/($db+243.5));

$Es = $H;

$I = $Ew - $pr*($db-$wb)*.00066*(1+(.00115*wb));

$Vpres = $I;

$J = ($Vpres/$Es)* 100;
$rh = $J;
$rh = round($rh,3);



$do = $Vpres/6.112;
$logs = Log10($do); 
$Dp = round(((237.7 * $logs)/(7.7-$logs)),3);

echo "<br>";
echo "&nbsp";
echo "&nbsp";

echo "<input type='text' size='4' name='name' value='$rh'> % Relative Humidity";
echo "<br>";
echo "<br>";
echo "&nbsp";

echo " <input type='text' size='4' name='name' value='$Dp'> Dewpoint";}// calc closing brace d

Thanks,

Paul

Link to comment
Share on other sites

Ok something clobbered the post I'm going to try the code again

 

function calc($db, $wb, $pr){ //opening brace calc b

if ( ! preg_match('/^\d+$/', $db) || ! preg_match('/^\d+$/', $wb) || ! preg_match('/^\d+$/', $pr)) 
{ // if opening brace c


echo "<br>";

echo "&nbsp";
echo "&nbsp";
echo "<input type='text' size='14' name='error' value='Numbers Only!'>";} //if closing brace c


else { //  else opening brace d

//Calculation Begins

$F = 6.112 * exp((17.67*$wb)/($wb+243.5));

$Ew = $F;


$H = 6.112 * exp((17.67*$db)/($db+243.5));

$Es = $H;

$I = $Ew - $pr*($db-$wb)*.00066*(1+(.00115*wb));

$Vpres = $I;

$J = ($Vpres/$Es)* 100;
$rh = $J;
$rh = round($rh,3);



$do = $Vpres/6.112;
$logs = Log10($do); 
$Dp = round(((237.7 * $logs)/(7.7-$logs)),3);

echo "<br>";
echo "&nbsp";
echo "&nbsp";

echo "<input type='text' size='4' name='name' value='$rh'> % Relative Humidity";
echo "<br>";
echo "<br>";
echo "&nbsp";

echo " <input type='text' size='4' name='name' value='$Dp'> Dewpoint";}// calc closing brace d

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.