Jump to content

Call to undefined function.


bigboss

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.