CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   General web building (http://www.codingforums.com/forumdisplay.php?f=10)
-   -   Problem with calling a file. (http://www.codingforums.com/showthread.php?t=272257)

phil1ooo 09-04-2012 10:32 PM

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

_Aerospace_Eng_ 09-05-2012 02:02 AM

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.

phil1ooo 09-05-2012 02:22 AM

1 Attachment(s)
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

_Aerospace_Eng_ 09-05-2012 02:30 AM

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.

phil1ooo 09-05-2012 03:23 AM

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.

phil1ooo 09-05-2012 04:25 AM

Quote:

Originally Posted by Teresa460 (Post 1267042)
I wasn't sure which forum to place this in so please feel free to move me if need be.http://www.movieia.info/ht7.jpghttp://www.movieia.info/jh88.jpghttp://www.movieia.info/dh5.jpg


And this is suppose to mean what exactly please!

_Aerospace_Eng_ 09-05-2012 04:40 AM

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.

phil1ooo 09-05-2012 07:41 AM

Quote:

Originally Posted by _Aerospace_Eng_ (Post 1267051)
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;
Quote:

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

_Aerospace_Eng_ 09-05-2012 02:42 PM

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);
    }
?>


phil1ooo 09-05-2012 03:14 PM

1 Attachment(s)
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

mlseim 09-05-2012 03:20 PM

Give us a link to the actual website so we can see it.

phil1ooo 09-05-2012 04:04 PM

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

mlseim 09-05-2012 05:39 PM

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



.

phil1ooo 09-05-2012 09:09 PM

Quote:

Originally Posted by mlseim (Post 1267215)
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

mlseim 09-05-2012 09:34 PM

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.


All times are GMT +1. The time now is 12:59 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.