leothelion Posted November 5, 2008 Share Posted November 5, 2008 why does the following test not work only if the number 0 is entered? if ($_POST['ipaddr'] >= '1' && $_POST['ipaddr'] <= '254') { echo "<br>good number"; } else { echo "<br>Please enter a number between 1 and 254"; } exit(); when 0 is entered I see a blank screen - if I enter 255 or greater I see "please enter a number... Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/ Share on other sites More sharing options...
limitphp Posted November 5, 2008 Share Posted November 5, 2008 I could be wrong here, but should you take off the quotes from around the 1 and the 254? So should it be like this instead?: if ($_POST['ipaddr'] >= 1 && $_POST['ipaddr'] <= 254) { Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683114 Share on other sites More sharing options...
flyhoney Posted November 5, 2008 Share Posted November 5, 2008 You might want to print_r($_POST) and make sure that $_POST['ipaddr'] really is 0. Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683115 Share on other sites More sharing options...
leothelion Posted November 5, 2008 Author Share Posted November 5, 2008 single double or no quotes - no difference. I did try echo'ing the input value. In all cases it shows as entered except for zero - blank screen. Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683118 Share on other sites More sharing options...
flyhoney Posted November 5, 2008 Share Posted November 5, 2008 So it looks like the code is fine the information is just not getting posted. Is there any sort of javascript validation happening? Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683127 Share on other sites More sharing options...
Maq Posted November 5, 2008 Share Posted November 5, 2008 Could you post the entire code, from when you get the data till when you pass it? Also, could you turn on error reporting/displaying? ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683138 Share on other sites More sharing options...
Yesideez Posted November 5, 2008 Share Posted November 5, 2008 I would try this and see how it goes... if (intval($_POST['ipaddr'])>=1 && intval($_POST['ipaddr'])<=254) { I can't see anything else that could be up with this - it's probably the actual contents of 'ipaddr' not being a single integer. I'm thinking that it stands for "IP Address" and if so, might want to try using echo to show the contents of the $_POST var immediately before the above if(). echo 'DEBUG: '.$_POST['ipaddr']; Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683183 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2008 Share Posted November 5, 2008 The posted lines of code won't ever give a blank screen. Something else in your code would be causing that. Post your actual code. Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683189 Share on other sites More sharing options...
leothelion Posted November 5, 2008 Author Share Posted November 5, 2008 here's the entire program as requested...thanks <html><head><title>jim ></title></head> <body> <?php function check_ipaddr($arg) { // checks to see if dns record exists for ipaddr passed // if yes returns true exec("dig -x $arg +short",$diga); if ($diga) return true; } function check_hostname($arg1) { // checks to see if dns record exists for hostname passed // if yes returns true exec("dig $arg1 +short",$diga); if ($diga) return true; } if($_SERVER['REQUEST_METHOD'] == 'GET') { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"> Enter hostname: <input type=text name=hostname><br> Enter IP number: 123.56.134. <input type=text maxlength=3 size=3 name=ipaddr><br> <input type=submit value="Check It"> <input type=reset> </form> <?php } else { if (!empty($_POST['hostname'])) { $hostname = $_POST['hostname'].".example.com"; if (check_hostname($hostname)) { echo "<br>That hostname $hostname is already in use"; } else { echo "<br>That hostname $hostname is free"; } } if (!empty($_POST['ipaddr'])) { echo $_POST['ipaddr']; if ($_POST['ipaddr'] >= 1 && $_POST['ipaddr'] <= 254) { $ipaddr = "123.56.134.".$_POST['ipaddr']; if (check_ipaddr($ipaddr)) { echo "<br>That ipaddr ".$ipaddr." is already in use"; } } else { echo "<br>Please enter a number between 1 and 254"; exit(); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683284 Share on other sites More sharing options...
leothelion Posted November 5, 2008 Author Share Posted November 5, 2008 sorry...i'm working from home now and screwed up the cut/paste from a dos telnet session. the last piece of code looks like this if (!empty($_POST['ipaddr'])) { echo $_POST['ipaddr']; if ($_POST['ipaddr'] >= 1 && $_POST['ipaddr'] <= 254) { $ipaddr = "204.62.134.".$_POST['ipaddr']; if (check_ipaddr($ipaddr)) { echo "<br>That ipaddr ".$ipaddr." is already in use"; } else { echo "<br>That ipaddr $ipaddr is free"; } } else { echo "<br>Please enter a number between 1 and 254"; exit(); } } } ?> </body></html> ~ Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683290 Share on other sites More sharing options...
leothelion Posted November 6, 2008 Author Share Posted November 6, 2008 I should have been using isset rather than !empty. !empty will not work for 0 0 is considered empty in php even if the user typed in a numeric 0 as input. this was causing the program to fall through all the logic producing the blank screen. not exactly intuitive.... Quote Link to comment https://forums.phpfreaks.com/topic/131530-solved-i-give-up-validation-test-not-working/#findComment-683737 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.