Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Problem with calling a file.

    Hi all

    I am using a calculator script which I downloaded for free. It works when I call the file directly from the url mysite.com/filename but when I call it using an "include" it doesn't work.


    This has 2 files being a .php and .tpl.

    If I use just the filename with my include everything below that page (footer) doesn't work. If I use (../filename) the footer works but the script doesn't show up on the page.

    The read me on this script stats that we just need to correct the url in the .php file which I have done. In the .tpl file there is nowhere which I can see that the url is displayed nor does it have the .php file being called within it.

    Can anyone help please.

    Cheers
    Ozy Industries Pty Ltd offers Domain sales, webhosting, email marketing, Advertising and much more at cheap rates. http://www.ozydomains.com.au
    http://www.ozyauctions.com.au

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    We would need to see the php and tpl files. A link to where you got it might help too. This probably belongs in the php forum. Don't cross post though.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    phil1ooo (09-05-2012)

  • #3
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Hi

    I wasn't sure which forum to place this in so please feel free to move me if need be.

    As for the file it can be download here http://www.pc-calculators.com/loan-calculator.php as it is a free calculator but also proabably the best one I have seen yet. I want it for a car sales website.

    I will attach the files here as well.

    Cheers
    Attached Files Attached Files
    Ozy Industries Pty Ltd offers Domain sales, webhosting, email marketing, Advertising and much more at cheap rates. http://www.ozydomains.com.au
    http://www.ozyauctions.com.au

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You would see why it doesn't work if you had warnings turned on. On line 38 of the php script it loads the tpl file. Modify that to reflect the path to your file.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    phil1ooo (09-05-2012)

  • #5
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Hi

    Sorry to sound amiturish here but I am no php coder but do understand html.

    What is warnings as the path file reads
    PHP Code:
    extract(load_template("loan-calculator.tpl")); 
    this on line 38 which as far as I know is directly to the root of where the file is.

    If the warnings thing is done somewhere esle then please tell me.
    Ozy Industries Pty Ltd offers Domain sales, webhosting, email marketing, Advertising and much more at cheap rates. http://www.ozydomains.com.au
    http://www.ozyauctions.com.au

  • #6
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Teresa460 View Post
    I wasn't sure which forum to place this in so please feel free to move me if need be.

    And this is suppose to mean what exactly please!
    Ozy Industries Pty Ltd offers Domain sales, webhosting, email marketing, Advertising and much more at cheap rates. http://www.ozydomains.com.au
    http://www.ozyauctions.com.au

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    don't worry about that post it is just a spammer. At the top of the page you are including the php on add the following.
    PHP Code:
    <?php
    ini_set
    ('display_errors','On');
    error_reporting(E_ALL);
    ?>
    Are you sure it is in the root? It does come in a folder called phpLoanCalc.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    phil1ooo (09-05-2012)

  • #8
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    don't worry about that post it is just a spammer. At the top of the page you are including the php on add the following.
    PHP Code:
    <?php
    ini_set
    ('display_errors','On');
    error_reporting(E_ALL);
    ?>
    Are you sure it is in the root? It does come in a folder called phpLoanCalc.
    Hi and thank you

    Firstly Yes it was in the root dir but I have now changed it to the same directory as where the file I am placing the include in is which you will see below.

    This is a copy of the error shown;
    Fatal error: Cannot redeclare strip() (previously declared in /home/myserver/public_html/filename/filename.php:783) in /home/myserver/public_html/extensions/loan-calculator.php on line 175
    Now here is a copy of what is on that line and lines around it.
    PHP Code:
    }
    function 
    strip($value)
    {
    if(
    get_magic_quotes_gpc() == 0)
    return 
    $value;
    else
    return 
    stripslashes($value);

    Line 783 is the one that starts with the word "function" .

    If allowed as I am not sure I can either place a link to me site page in question here or MP it to you which ever is fine by me if you feel that might help some.

    Cheers
    Last edited by phil1ooo; 09-05-2012 at 08:43 AM.
    Ozy Industries Pty Ltd offers Domain sales, webhosting, email marketing, Advertising and much more at cheap rates. http://www.ozydomains.com.au
    http://www.ozyauctions.com.au

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Are filename and loan-calculator.php the same files or are they different files? The reason it isn't working is exactly because of that error. In filename.php you have a function called strip however in loan-calculator.php there is also a function called strip. Easiest thing to do would probably to rename the function in the loan-calculator.php file and do a find and replace in that file to fix the function calls. I have done this for you in the following code. Replace your code in loan-calculator.php with the following.
    PHP Code:
    <?php
        
        
    /**
         * Project:     phpLoanCalc v1.0
         * Files:       loan-calculator.php
         *              loan-calculator.tpl
         *
         * This library is free software; you can redistribute it and/or
         * modify it under the terms of the GNU General Public License
         * as published by the Free Software Foundation; either version 2.1
         * of the License, or (at your option) any later version.
         *
         * The footer text along with the link("Powered by PC-Calculators.com") 
         * MUST NOT BE REMOVED, otherwise any use of the software will be constituted
         * as a breach of copyright. Please, contact scripts@pc-calculators.com
         * for commercial inquiries and licensing.
         * 
         * This library is distributed in the hope that it will be useful,
         * but WITHOUT ANY WARRANTY; without even the implied warranty of
         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
         * General Public License for more details.
         *
         * You should have received a copy of the GNU General Public License
         * along with this software; if not, write to the Free Software
         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
         *
         * For questions, commercial inquiries, licensing, help, comments, discussion,
         * etc., please contact scripts@pc-calculators.com
         *
         * @link http://www.pc-calculators.com/
         * @copyright 2004 ArsRef, LLC.
         * @author Arseniy Olevskiy <arseniy@pc-calculators.com>
         * @package phpLoanCalc
         * @version 1.0
         */

        /* Loading template */
        
    extract(load_template("loan-calculator.tpl"));
        
        
    /* Defining Variables */
        
    $periods = array(
                        
    52 => 'Weekly',
                        
    26 => 'Bi-weekly',
                        
    12 => 'Monthly',
                        
    => 'Bi-monthly',
                        
    => 'Quarterly',
                        
    => 'Semi-annually',
                        
    => 'Annually'
                        
    );
        
    $loan_amount     = isset($_GET["loan_amount"])     ? $_GET["loan_amount"]     : 150000;
        
    $loan_length     = isset($_GET["loan_length"])     ? $_GET["loan_length"]     : 10;
        
    $annual_interest = isset($_GET["annual_interest"]) ? $_GET["annual_interest"] : 7;
        
    $pay_periodicity = isset($_GET["pay_periodicity"]) ? $_GET["pay_periodicity"] : 12;
        
    $periodicity     $periods[$pay_periodicity];
        
        
    $pay_periods '';
        foreach(
    $periods as $value => $name)
        {
            
    $selected = ($pay_periodicity == $value) ? 'selected' '';
            
    $pay_periods .= replace_vars($pay_period_option);
        }
        
        
    /* Checking Variables */
        
    if(!is_numeric($loan_amount) or $loan_amount <= 0
            { 
    $error "<p><font color=red>Loan amount</font> has to be numeric and greater than zero.</p>"; }

        if(!
    is_numeric($loan_length) or $loan_length <= 0
            { 
    $error "<p><font color=red>Loan length</font> has to be numeric and greater than zero.</p>"; }

        if(!
    is_numeric($annual_interest) or $annual_interest <= 0
            { 
    $error "<p><font color=red>Annual interest</font> has to be numeric and greater than zero.</p>"; }

        
    /*
        *----------------------------------
        *    Calculating and displaying
        *----------------------------------
        */
        
        /* Process Loan Parameters Form in any case */
        
    $loan_parameters_form replace_vars($loan_parameters_form);

        
    /* If no error, then begin calculations */
        
    if(!isset($error) && isset($_GET['action']))
        {
            
    $c_balance         $loan_amount;
            
    $total_periods     $loan_length $pay_periodicity;
            
    $interest_percent  $annual_interest 100;
            
    $period_interest   $interest_percent $pay_periodicity;
            
    $c_period_payment  $loan_amount * ($period_interest / (pow(($period_interest), -($total_periods))));
            
    $total_paid        number_format($c_period_payment $total_periods2'.'' ');
            
    $total_interest    number_format($c_period_payment $total_periods $loan_amount2'.'' ');
            
    $total_principal   number_format($loan_amount2'.'' ');

            
    $loan_amount     number_format($loan_amount2'.'' ');
            
    $annual_interest number_format($annual_interest2'.'' ');
            
    $period_payment  number_format($c_period_payment2'.'' ');
            
            
    $amortization_table_rows '';
            for(
    $period 1$period <= $total_periods$period++)
            {
                
    $c_interest  $c_balance $period_interest;
                
    $c_principal $c_period_payment $c_interest;
                
    $c_balance  -= $c_principal;
                
                
    $interest  number_format($c_interest2'.'' ');
                
    $principal number_format($c_principal2'.'' ');
                
    $balance   number_format($c_balance2'.'' ');
                
                
    $evenrow_row_modifier = ($period 2) ? '' 'class=evenrow';

                
    $amortization_table_rows .= replace_vars($amortization_table_row);
            }
        }
        else
        {
            
    $amortization_table '';
            
    $loan_summary '';
        }
        
    $body replace_vars($body);
        
        
    /* If headers sent, then it means that the script is used as inclusion */
        
    if(!headers_sent())
        {
            
    $send_footer true;
            echo 
    loan_strip($header);
        }
        
        echo 
    loan_strip(replace_vars($body));

        if(isset(
    $send_footer))
        {
            echo 
    loan_strip($footer);
        }
        
        
    /*
        *----------------------------------
        *            Functions
        *----------------------------------
        */
        
        
    function replace_vars($tpl)
        {
            return 
    preg_replace_callback("/\{(.+?)\}/""glb"$tpl);
        }
        
        function 
    glb($m)
        {
            if(isset(
    $GLOBALS[$m[1]]))
            {
                return 
    $GLOBALS[$m[1]];
            }
        }
        
        function 
    load_template($path)
        {
            
    /* Loads template from file */
            
    $h fopen($path"r");
            
    $file fread($hfilesize($path));
            
    fclose($h);
            
            
    preg_match_all('/<!-- BEGIN (.+?) -->(.+?)<!-- END \1 -->/is'$file$m);
            
            for(
    $i=0$i<count($m[1]); $i++)
            {
                
    $template[$m[1][$i]] = $m[2][$i];
            }
            
            return 
    $template;
        }

        function 
    loan_strip($text)
        {
            
    /* Removes New Line characters and multiple spaces */
            
    return preg_replace('/\s+/'' '$text);
        }
    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    phil1ooo (09-05-2012)

  • #10
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Hello

    OK this is now working WOW thank you very much.

    BUT it now leaves another unexpected issue.

    As you will see in the screenshot I have take when I call the file directly using [www. sitename.com/ loan-calculator. php ] the calculator works exactly as it should.

    Now on my website the first box now shows up (thanks to you) but when I click on "calculate" it doesn't work.

    Any thoughts as to why please.

    Cheers
    Attached Thumbnails Attached Thumbnails Problem with calling a file.-9-6-2012-12-04-19-am.jpg  
    Ozy Industries Pty Ltd offers Domain sales, webhosting, email marketing, Advertising and much more at cheap rates. http://www.ozydomains.com.au
    http://www.ozyauctions.com.au

  • #11
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    Give us a link to the actual website so we can see it.

  • Users who have thanked mlseim for this post:

    phil1ooo (09-14-2012)

  • #12
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Hi There

    http://www.ozyautos.com.au/sale/1/1/...46-in-new.html

    This website is still under constrution and the link is to the page in question.

    Cheers
    Ozy Industries Pty Ltd offers Domain sales, webhosting, email marketing, Advertising and much more at cheap rates. http://www.ozydomains.com.au
    http://www.ozyauctions.com.au

  • #13
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    This is how you define your form tag: <form>

    So when submit is clicked, the form calls itself (the page it's on) and refreshes the screen.

    You are never processing it, because it never executes "loan-calculator.php"


    Even if you executed it by doing this ....
    <form action="loan-calculator.php" method="post">
    I think it would display the loan calculator but not the other page.

    You're going to need in the least, some javascripting.
    In fact, the whole loan calculator should be javascripting.
    Better yet, JQuery.

    If PHP is required to dynamically put numbers into the load "widget",
    you'll end-up using AJAX, which is a combination of PHP and JQuery.

    Scrap what you're using now and look at some of these:
    http://www.google.com/search?q=php+a...or&btnG=Search



    .

  • Users who have thanked mlseim for this post:

    phil1ooo (09-05-2012)

  • #14
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    Scrap what you're using now and look at some of these:
    http://www.google.com/search?q=php+a...or&btnG=Search
    Hi
    Please don't misunderstand me here I do appreciate your suggestion as all ideas are some merit which may suit or may not.
    But please check this out first.

    I am no expert in php but if you look at this link http://www.ozyautos.com.au/loan-calculator.php which is a as you would already know a direct link to the loan calculator and try it there it will work exactly as it should.

    So if it's working on my server out of the same root dir but not when it's been called with my script wouldn't you say that the most likely reason it's not working would be because the 2 scripts are conflicting somewhere and it's just a matter of finding out where as Aerospace was able to do above.

    I have looked at calculator scripts for over 2 weeks now and this is by far the best one I have seen and it actually works where many others don't even on heir own demo sites.

    Cheers
    Ozy Industries Pty Ltd offers Domain sales, webhosting, email marketing, Advertising and much more at cheap rates. http://www.ozydomains.com.au
    http://www.ozyauctions.com.au

  • #15
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    OK ...

    Let me ask this question first ...

    When the user wants to use your loan "widget",
    it is OK if the whole page refreshes each time they click 'calculate'?

    The answer to that will determine the method you need to use.

  • Users who have thanked mlseim for this post:

    phil1ooo (09-05-2012)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •