p3aul Posted October 11, 2008 Share Posted October 11, 2008 Hi! [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/ Share on other sites More sharing options...
Lamez Posted October 11, 2008 Share Posted October 11, 2008 people would rather you post the problem, and the code. Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-662409 Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 Yes, post the problem. What is exactly happening? Any errors? Then post the "relevant" parts of code that are the cause of the problem. Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-662412 Share on other sites More sharing options...
p3aul Posted October 11, 2008 Author Share Posted October 11, 2008 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 " "; echo " "; 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 Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-662429 Share on other sites More sharing options...
hitman6003 Posted October 11, 2008 Share Posted October 11, 2008 Cast the values into integers (or floats, if that's what they are): if( (int) $db < (int) $wb) Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-662449 Share on other sites More sharing options...
p3aul Posted October 11, 2008 Author Share Posted October 11, 2008 if( (int) $db < (int) $wb) Ok I tried that using float , int, and double but it made no difference Paul Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-662473 Share on other sites More sharing options...
p3aul Posted October 12, 2008 Author Share Posted October 12, 2008 :'( Please someone help me with this before it gets buried in all the recent posts :'( Thanks, Paul Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-663207 Share on other sites More sharing options...
Maq Posted October 12, 2008 Share Posted October 12, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-663217 Share on other sites More sharing options...
p3aul Posted October 12, 2008 Author Share Posted October 12, 2008 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-663366 Share on other sites More sharing options...
Maq Posted October 12, 2008 Share Posted October 12, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-663513 Share on other sites More sharing options...
p3aul Posted October 12, 2008 Author Share Posted October 12, 2008 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 " "; echo " "; 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 " "; echo " "; echo "<input type='text' size='4' name='name' value='$rh'> % Relative Humidity"; echo "<br>"; echo "<br>"; echo " "; echo " <input type='text' size='4' name='name' value='$Dp'> Dewpoint";}// calc closing brace d Thanks, Paul Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-663555 Share on other sites More sharing options...
p3aul Posted October 12, 2008 Author Share Posted October 12, 2008 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 " "; echo " "; 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 " "; echo " "; echo "<input type='text' size='4' name='name' value='$rh'> % Relative Humidity"; echo "<br>"; echo "<br>"; echo " "; echo " <input type='text' size='4' name='name' value='$Dp'> Dewpoint";}// calc closing brace d Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-663556 Share on other sites More sharing options...
p3aul Posted October 12, 2008 Author Share Posted October 12, 2008 If you can't read that I will try to upload itThanks, Paul Quote Link to comment https://forums.phpfreaks.com/topic/127933-if-statement-doest-seem-to-work/#findComment-663558 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.