Forum Moderators: coopster

Message Too Old, No Replies

Php help, undefined variables

..

         

BahamutG

8:11 pm on Dec 23, 2003 (gmt 0)

10+ Year Member


I'm just learning php, and I have php on my pc. I used this tutorial and for some reason when I try to do a form thing, I get an error. Here:
loanshark_html.html (
<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>
)

loanshark.php (
<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($cost, $interest_rate);

?>

</body>
</html>
)

result (
Notice: Undefined variable: cost in c:\program files\easyphp1-7\www\tests\loanshark.php on line 45
You better pay me $0 every week, or else! )

Is there something wrong with my php settings? or what? can someone help out?

jatar_k

8:17 pm on Dec 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



because $cost is coming from a posted form it will be located inside the $_POST superglobal array [ca.php.net]. It can be accessed in one of these manners

extract($_POST); //this would be located at, or near, the top of the code

$cost = $_POST['cost'];

or just use $_POST['cost'] instead of $cost

BahamutG

11:22 pm on Jan 4, 2004 (gmt 0)

10+ Year Member



Sorry, I thought I said thanks for that.

Well..now..i try to do:
echo $HTTP_USER_AGENT;
and i get that "Notice: Undefined variable: HTTP_USER_AGENT in c:\program files\easyphp1-7\www\tests\tests.php on line 14" thing again. Is there another thing I have to do with this?

bofe

11:34 pm on Jan 4, 2004 (gmt 0)

10+ Year Member



try using $_SERVER['HTTP_USER_AGENT']

BahamutG

11:49 pm on Jan 4, 2004 (gmt 0)

10+ Year Member



thanks