...

View Full Version : Problem with calling a file.



phil1ooo
09-04-2012, 11:32 PM
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, 03: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, 03:22 AM
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, 03: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, 04: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
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, 05:25 AM
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, 05: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
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, 08:41 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
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.


}
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, 03: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

/**
* 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',
6 => 'Bi-monthly',
4 => 'Quarterly',
2 => 'Semi-annually',
1 => '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 / (1 - pow((1 + $period_interest), -($total_periods))));
$total_paid = number_format($c_period_payment * $total_periods, 2, '.', ' ');
$total_interest = number_format($c_period_payment * $total_periods - $loan_amount, 2, '.', ' ');
$total_principal = number_format($loan_amount, 2, '.', ' ');

$loan_amount = number_format($loan_amount, 2, '.', ' ');
$annual_interest = number_format($annual_interest, 2, '.', ' ');
$period_payment = number_format($c_period_payment, 2, '.', ' ');

$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_interest, 2, '.', ' ');
$principal = number_format($c_principal, 2, '.', ' ');
$balance = number_format($c_balance, 2, '.', ' ');

$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($h, filesize($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, 04:14 PM
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, 04:20 PM
Give us a link to the actual website so we can see it.

phil1ooo
09-05-2012, 05:04 PM
Hi There

http://www.ozyautos.com.au/sale/1/1/2012-alfa-romeo-146-in-new.html

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

Cheers

mlseim
09-05-2012, 06: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+ajax+loan+calculator&btnG=Search



.

phil1ooo
09-05-2012, 10:09 PM
Scrap what you're using now and look at some of these:
http://www.google.com/search?q=php+ajax+loan+calculator&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 (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, 10: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.

phil1ooo
09-05-2012, 10:47 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.

Hi

Yes as the page refreshed can't loss details anyway.

But I have it working now if you click on the link I gave earlier to my website page and test it out it is working I just need to fix up the apperance now of what is shown once clicked on.

That part is no problem.

Thank you

phil1ooo
09-05-2012, 10:51 PM
This issue is now resloved and I give a Big Thanks to Aerospace :thumbsup: for all his efforts in solving my problem.

Also I thank those who had other suggestions as all suggestions are very welcomed.

phil1ooo
09-06-2012, 01:41 AM
As this is on the same topic I will continue here.

This code within the php file

if(isset($mod))
{

$file = str_replace("<form>","<form action=\"http://www.ozyautos.com.au/calculator.php\"><input type=hidden name=mod value=re_search><input type=hidden name=ad_type value=sale><input type=hidden name=type value=\"".$type."\"><input type=hidden name=ad value=\"".$ad."\">",$file);

}


brings up the results on a new page thus the calculator.php page which I have created but I would prefer this page to be opened in a new window and be smaller.

I have tried using "target" but that doesn't seem to be working in the php file.

Can anyone help here please?

Cheers

marry1
09-14-2012, 09:57 AM
Can you give the link to me?

phil1ooo
09-14-2012, 12:13 PM
For more information on how PHP handles including files and the include path, see the documentation for include path.

Hi and Thank You

The problem wasn't the actual include path as I had that correct. It was (and I'm no php expert so please excuse my terms of expression here) a line which apparently need to be added at the end of the page within the php file that told the include path to accept being called, or so to spect to accept the call.

That's close to how a programmer I found explained it to me.

The other problem with the open a new window was that I didn't place a (\) before the (")s, again I had that partly correct except for that slash.

I am tring to learn the php but unfortunately rome wasn't build it a day. (2 maybe) LOL.

Cheers



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum