FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP tutorial - Grand Master Functions





Tony The Tiger
I am now trying to do page 11 of the tutorial. I am getting the following error:

Parse error: parse error, expecting `')' in c:\program files\easyphp1-8\www\loanshark.php on line 9

I have adjusted the tutorial's loanshark.php code as follows

<html> <head> <title>Loans</title> </head>

<body>

<?php

$interest_rate = .14;


function YouOweMe($_POST['cost'], $_POST['interest_rate'])

{

$weekly_payment = ($cost*$interest_rate);

print "You better pay me \$$weekly_payment every week, or else!";

}

YouOweMe($cost, $interest_rate);

?>


</body> </html>

print $_POST['YourName'];


I also use the tutorial's html code as follows:

<html>
<head>
<title>"You Better Pay Up" Loan Services</title>
</head>

<body>

<center>

<h3>Welcome to "You Better Pay Up" Loan Services</h3>

You pay us ten percent every week, or else.

<form action="loanshark.php" method=post>


My hovercraft costs $<input type="text" name="cost"> <p><input
type="submit" name="submit" value="What's My Interest Payment?">

</form>

</center>

</body> </html>
johanfh
Tony The Tiger wrote:


function YouOweMe($_POST['cost'], $_POST['interest_rate'])

<form action="loanshark.php" method=post>

My hovercraft costs $<input type="text" name="cost"> <p><input
type="submit" name="submit" value="What's My Interest Payment?">

</form>



Hi Tony,
I looked through your script and I think I've found the bug. You want to get 'interest_rate' by posting it, but you don't post it! You only post 'cost' but $interest_rate is defined in line 7
So line 9 should be:
function YouOweMe($_POST['cost'],$interest_rate)

I hope this might help you,
good luck!

JohanFH
Tony The Tiger
johanfh wrote:

Hi Tony,
You want to get 'interest_rate' by posting it, but you don't post it! You only post 'cost' but $interest_rate is defined in line 7
So line 9 should be:
function YouOweMe($_POST['cost'],$interest_rate)

I hope this might help you,
good luck!

JohanFH


same error.
Tony The Tiger
It is now working with

<html> <head> <title>Loans</title> </head>

<body>

<?php

$interest_rate = .14;

function YouOweMe($cost, $interest_rate) {

$weekly_payment = ($cost*$interest_rate);

print "You better pay me \$$weekly_payment every week, or else!";

}

YouOweMe($_POST['cost'], $interest_rate);

?>


</body> </html>
johanfh
Hmm, at the moment I can't test it, but I have an other idea Idea
But: I'm not very good at PHP (I mostly use Perl)!

What your script does is defining a function YouOweMe that relates to the variables ? and ? (not defined).
Later on you call that function with $cost and $interest_rate, but you didn't define $cost (you get the data from the other script with your $_POST command but you don't store it in anything)

So I guess it should look like this:

$cost= $_POST['cost'];
$interest_rate = '.14'; (or ... = $_POST['interest_rate']; )

function YouOweMe($cost,$interest_rate);
{
...
}

YouOweMe($cost,$interest_rate);
and this last line might even be:
YouOweMe($_POST['cost'],$_POST['interest_rate']);
because the script already knows from line 9 that the first argument is $cost and the second is $interest_rate.

I hope this works! (Let me know)

JohanFH
Related topics
Complete Tutorial LINKS for every language
PHP Tutorials
PHP Tutorial: Basic Shoutbox w/ MySQL
PHP OOP Tutorial
php tutorial
A very good PHP MySQL Tutorial
Cancelled tv shows
PHP 5.x print functions ? [ printer ]
PHP Tutorial
Flex and PHP tutorial
Flex and PHP tutorial
Learning PHP
php tutorial
How to Enable PHP IMAP eMail Functions
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.