bigboss Posted March 17, 2009 Share Posted March 17, 2009 Hello, I am writing a validate function that works by passing the post value, the type of field and if the field is required. In my register page I call the function like: <?php validate($_POST['username'],'username',1); ?> The function is stored in a separate functions page in a functions directory. The code for the function is as folllows: <?php function validate($post_value,$field_type,$required){ if(isset($_POST[$post_value]) && (!empty($post_value)) || !$required){ }else{ } ?> I have included the functions page with <?php include 'functions/functions.php'; ?> But yet when I debug or run the code it seems as if my code can't see the function even though it enters the functions.php file. Have you guys got any ideas why this would be happening? Quote Link to comment https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/ Share on other sites More sharing options...
Adam Posted March 17, 2009 Share Posted March 17, 2009 Do you have errors disabled at all? Try adding: error_reporting(E_ALL); ini_set('display_errors', '1'); ...to the top of your code. Adam Quote Link to comment https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/#findComment-786595 Share on other sites More sharing options...
kickstart Posted March 17, 2009 Share Posted March 17, 2009 Hi Where do you have the include statement in relation to where you are calling the function? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/#findComment-786604 Share on other sites More sharing options...
bigboss Posted March 17, 2009 Author Share Posted March 17, 2009 The include statement is above the call to the function. The whole structure of the register page is: <?php include 'config.php'; include 'functions/functions.php'; if(isset($_POST)){ } else { } ?> Also all errors are reporting. Quote Link to comment https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/#findComment-786608 Share on other sites More sharing options...
Adam Posted March 17, 2009 Share Posted March 17, 2009 ..And you've tried debugging the functions.php file by adding something like.. die('here?'); to the top of it? Quote Link to comment https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/#findComment-786612 Share on other sites More sharing options...
Mikedean Posted March 17, 2009 Share Posted March 17, 2009 Your function is wrong anyway. It should read. function validate($post_value,$field_type,$required) { if(isset($post_value) && !empty(trim($post_value)) || !$required) { } else { } } This might in turn fix the problem so worth a try . Quote Link to comment https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/#findComment-786619 Share on other sites More sharing options...
bigboss Posted March 17, 2009 Author Share Posted March 17, 2009 Why would I want to trim? Quote Link to comment https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/#findComment-786623 Share on other sites More sharing options...
syed Posted March 17, 2009 Share Posted March 17, 2009 Personally, I would create a Validate Class which consists of the different validations for various types, Such as integers, strings, email fields, etc.. rather than having one function to deal with all validation types. That's just my opinion. Quote Link to comment https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/#findComment-786625 Share on other sites More sharing options...
bigboss Posted March 17, 2009 Author Share Posted March 17, 2009 I would like to have a validation class, but the only OOP experience I've had in the past is Java. I'm not sure how PHP implements polymorphism, inheritance and encapsulation. This project is only for a small website and it is easier for me to code a small function that to learn OOP rules in PHP and then code a class. Quote Link to comment https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/#findComment-786626 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.