Function is called in my functions file.

function Get_Favourites($fields){
    $member = $fields['fv_member'];
    $sql = "SELECT * FROM favourites ";
    $sql .= "WHERE FV_MEMBER='" . $member . "' ";
    $sql .= "ORDER BY FV_PRODUCT";

    return FetchSqlAsObjectArray($sql);
}

Functions file is called in my header and is working with other functions.

<?php
include_once("includes/session.php");
confirm_logged_in();
?>
<?php
include_once("../includes/masterinclude.php");
$pageTitle = 'Favourites';
$pageSubTitle='Favourites';
include_once("includes/header_sidebar.php");


$information = getInformationPage("Favourites");
$preferences = getPreferences();
$pageTitle = "Favourites";
$top_level="0"; $infopagename="";
$pageMetaDescription = $preferences->PREF_META_DESC;
$pageMetaKeywords = $preferences->PREF_META_KEYWORDS;
if(!isset($_POST['favourites'])){$_POST['favourites'] = "";}

if(isset($_POST['DELETE_FAVOURITE']) and $_POST['DELETE_FAVOURITE'] == 1){
    //delete favourites entry
    $rows = Delete_Favourite($_POST['ID_TO_DELETE']);
}
?>
                    <?php
                    //$name = $_GET['page'];
                    $information = getInformationPage("Favourites");
                    echo html_entity_decode($information->IN_DATA, ENT_QUOTES);  
                    ?> 
                            </div>   
                            <?php
                            $member = Get_Member($_SESSION['username']);
                            $fields = array("fv_member"=>$member->MB_ID);
                            $favourites = Get_Favourites($fields);

                            if(count($favourites) > 0){
                                echo "<div class=\"matter\">";
                                    echo "<div class=\"container\">";
                                        echo "<div class=\"row\">";
                                            echo "<div class=\"col-md-12\">";
                                            echo "<div class=\"padd\">";
                                            echo "<form class=\"form-horizontal form-box\" role=\"form\" id=\"favourites\" action=\"favourites.php\" method=\"post\">";
                                            echo "<h4 class=\"form-box-header\">My Favourites</h4>";
                                            echo "<div class=\"form-box-content\">";
                                    echo "<ol>"; 
                                    //now scan down the favourites, read the product found and display it
                                    foreach($favourites as $f){
                                        $id = $f->FV_ID;
                                        $p = getProductDetails($f->FV_PRODUCT);
                                        $imagePathProd = "";
                                        if(strlen($p->PR_IMAGE_FOLDER) > 0){$imagePathProd = $p->PR_IMAGE_FOLDER . "/";}
                                        $imagePathProd .= $p->PR_IMAGE;
                                        if(strlen($imagePathProd) == 0){
                                            $imagePathProd = "/images/thumbnoimage.jpg";
                                        }else{
                                            $imagePathProd = "/images/" . $imagePathProd;
                                        }

                                        //$tree = getProductTree($p->PR_PRODUCT);
                                        //$link = "/" . urlencode(html_entity_decode($p->PR_NAME, ENT_QUOTES)) . "/" . $tree . "/" . $p->PR_PRODUCT . ".htm";

                                        //set link equal to the favourites table FV_URL (rather than generate it based on the product itself) since this represents the 
                                        //actual link clicked on ie. the same product may sit in different categories.
                                        $link = $f->FV_URL;
                                        echo
                                            "<li class=\"search-li\" style=\"height: 145px;\">
                                            <span>
                                                <a class=\"thumbnail-search\" href=\"" . $link . "\">
                                                    <img src=\"" . $imagePathProd . "\" alt=\"" . $p->PR_IMAGE_ALT . "\" height=\"100\" />
                                                </a>
                                                <input name=\"DELETE_FAV_" . $id . "\" id=\"DELETE_FAV_" . $id . "\" type=\"button\" 
                                                style=\"float: left; margin: 5px 0 0 6px; font-size: 11px;\" class=\"btn btn-primary\" value=\"Delete Favourite\" />
                                            </span>              
                                            <a class=\"thumbnail-search\" href=\"" . $link . "\">". html_entity_decode($p->PR_NAME, ENT_QUOTES) . "</a>
                                            <br />" . 
                                            html_entity_decode($p->PR_DESC_SHORT, ENT_QUOTES) . "
                                        </li>" . PHP_EOL;
                                    }
                                    echo "</ol>";

                                    echo "<div class=\"form-control\">";
                                        echo "<input name=\"DELETE_FAVOURITE\" id=\"DELETE_FAVOURITE\" type=\"hidden\" value=\"\" />";
                                        echo "<input name=\"ID_TO_DELETE\" id=\"ID_TO_DELETE\" type=\"hidden\" value=\"\" />";
                                    echo "</div>";
                                echo "</form>";
                            echo "</div>";
                        echo "</div>";
                    echo "</div>";
                echo "</div>";
            echo "</div>";
          }
        ?>

<?php
include 'includes/footer_notificationbox.php';
?>

<script type="text/javascript">
    $(document).ready(function(){
        $(".delete_fav_button").click(function(){
            var button_id = $(this).attr("name");
            var fav_to_delete = button_id.replace("DELETE_FAV_", "");
            $("#DELETE_FAVOURITE").val(1);
            $("#ID_TO_DELETE").val(fav_to_delete);
            $("#favourites").submit();
        });
    });
</script>

However I am getting the error message:

Fatal error: Call to undefined function get_favourites() in /home/download/domains/1ecommerce.com/public_html/dev/_cms/favourites.php on line 48

Any help would be really appreciated!

Have you made sure that the file is being included?

Yes It is being included via my masterinclude

<?php
include("dbopen.php");
include("mysql.php");
include("functions.php");
?>

You can check whether the correct file (the one that defines the function) has been included by executing print_r(get_included_files()); exit(); the line before the error.

Yes I have ran that line, It returned:

 /home/download/domains/1ecommerce.com/public_html/dev/_cms/favourites.php [1] => /home/download/domains/1ecommerce.com/public_html/dev/_cms/includes/session.php [2] => /home/download/domains/1ecommerce.com/public_html/dev/includes/masterinclude.php [3] => /home/download/domains/1ecommerce.com/public_html/dev/includes/dbopen.php [4] => /home/download/domains/1ecommerce.com/public_html/dev/includes/mysql.php [5] => /home/download/domains/1ecommerce.com/public_html/dev/_cms/functions.php [6] => /home/download/domains/1ecommerce.com/public_html/dev/_cms/includes/header_sidebar.php ) 

My Functions file is 100% being called. And the function is in there, this is confusing me so much!

Is the file being included before the function is called? Have you checked if there isn't a case problem (not that PHP functions are case sensitive, for as far as I know, but just to be sure)? Have you used get_defined_functions() to see if your function has actually been registered as defined?

Yes the master include file is being called in the first line of the code. Nope the cases match perfectly. Where would i write the get defined funbctions line, I have never used it before?

You could write it in the same place that you wrote the get_included_files() function, i.e. the line before the error.

Example: print_r(get_defined_functions()); exit();

That retuned all my functions bar the one I want which is Get_Favourites So does that mean it is not being defined correctly?

Well, if it is not in the list that is returned by get_defined_functions() there is something wrong, apparently :p. Is it in the list?

No it is not. Its the only function from my functions include that is not appearing in that list.

Well, maybe you could add some debug code to the file that contains that function that says "Hey, you've just included me!" and after that line something like var_dump(function_exists('Get_Favourites')); to see if the function has been defined (bottom lines of the function file).

Yes the function has not been defined

So if you add an echo to the file that defines your Get_Favourites() function, and then include that file, nothing is being echo'd to the screen? E.g. if you add echo 'Hey, you\'ve just included me!';, it doesn't show on the screen? Because if that is the case, you simply need to make sure that your file is properly included.

Do you mean put that echo in the Get_Favourites Function? The file is being included becasue get_included_files() returned saying it was.

The print_r(get_defined_functions()); exit(); returned all my functions in that file bar the Get_Favourites. Therefore the file is being called correctly it must be a problem with the function.

Well yes, it must be that, then. That's why I thought you could try to output var_dump(function_exists('Get_Favourites')); inside the file that defines the function (after the function is defined) to see if it really is a problem with the function definition. Have you tried that?

Yes it returns nothing I get the same error as before

Ok, this is confusing me somewhat: your file is in the list with included files, but if you output text inside that include file, it isn't being shown on the screen? Or does output get shown on the screen, and is it the "false" that is generated by var_dump(function_exists('Get_Favourites'));? Have you tried using different spelling for your function name and checking (with the function_exists() function) if the function does get defined properly with that spelling?

I tried outputting text from the functions file and that worked fine. If I include the function file directly it all works fine. Therefore it must be something to do with my master_include file.

Well, I'm glad you discovered the next clue ;). Let us know if you find anything that is wrong with it and if you need help with it.

Cheers for all your help really appreciate it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.