nicolanicola Posted October 25, 2009 Share Posted October 25, 2009 This is in an include file. I want it to check a value in an html form and see if it's just white space, is numbers, is empty etc. <?php function checkString($stringFieldName,$_GET){ $output="\n<p> "; $validate=true; if(array_key_exists($stringFieldName,$_GET)) { //trim any whitespace from values $string=trim($_GET[$stringFieldName]); //check if string value is empty if(empty($string)){ $output.="\nYou haven't entered any data in string<br />"; $validate=false; } if(is_numeric($string)){ $validate=false; $output.="You have entered a number instead of text"; } //if they have deleted values from url }else{ $output.="\nYou have deleted the characters from the url\n"; $validate=false; } echo $output."\n</p>"; } I am using it in a php file, the code is here: <?php echo "\n<p>"; include 'validateText&Number.inc'; checkString("surname",$_GET); if ($validate==false){ echo "\nYou did not enter the name correctly."; } else................. { When I type in actual text it tells me I have not entered name correctly which therefore means $validate must be false. I don't know how though it can be set to false because if the field just contains text, it isn't satisfying any of the conditions that lead to $validate=false. Please help!! Oh I'm a php newbie btw. Link to comment https://forums.phpfreaks.com/topic/178979-why-is-this-function-returning-a-false-value-when-it-shouldnt-be/ Share on other sites More sharing options...
Mark Baker Posted October 25, 2009 Share Posted October 25, 2009 Make sure that you return $validate from your function And don't pass $_GET as a parameter: it's a superglobal, which means it's actually in automatically scope from anywhere within your code Link to comment https://forums.phpfreaks.com/topic/178979-why-is-this-function-returning-a-false-value-when-it-shouldnt-be/#findComment-944296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.