Page 1 of 1

Plz Help regarding simple coding

Posted: Tue Feb 24, 2009 1:11 am
by waqar86
plz check my following code and tell me is there any error in it when i run it on my local mechine using WAMPSERVER it gives follwing error

Code: Select all

Notice: Undefined variable: salary in C:\wamp\www\loan.php on line 31
 
Notice: Undefined variable: age in C:\wamp\www\loan.php on line 32
 
Notice: Undefined variable: age in C:\wamp\www\loan.php on line 32
 
Notice: Undefined variable: loan in C:\wamp\www\loan.php on line 34
 
 
Loan Wanted:
 
Loan Amount We Will Allow U:0
 
 
Notice: Undefined variable: loan in C:\wamp\www\loan.php on line 37
 
Notice: Undefined variable: fname in C:\wamp\www\loan.php on line 38
 
Notice: Undefined variable: lname in C:\wamp\www\loan.php on line 38
Congrates. , We r delighted to offer u loan
Notice: Undefined variable: loan in C:\wamp\www\loan.php on line 40
 
but online it run smoothly http://waqar.w4wallpapers.com//loan.php
plz tell me where i m doing wrong??


here is code of that programe

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
  <title>Hello!</title>
</head>
 
<body>
<center><h1>Meezan Bank Loan Application Form</h1></center>
 
<form action="loan.php">
&nbsp;<b>First Name:</b>&nbsp;&nbsp; <Input type="Text" name="fname" />
&nbsp;<b>Last Name:</b>&nbsp;&nbsp; <Input type="Text" name="lname" />
&nbsp;<b>Age:</b>&nbsp;&nbsp; <Input type="Text" name="age" Size="3"/><br /><br />
&nbsp;<b>Address:</b>&nbsp;&nbsp; <textarea name="ads" rows="4" cols="40"></textarea><br /><br />
&nbsp;<b>Wht Is Ur Current Salary?</b>&nbsp;&nbsp;<select name="salary">
<option value="0">Less Then $10,000</option>
<option value="10000" >$10,000 To $25,000</option>
<option value="25000">$25,000 To $50,000</option>
<option value="50000">over $50,000</option>
</select><br /><br />
&nbsp;<b>How Much Loan U Want:</b>&nbsp;&nbsp;<br /><input type="radio" name="loan" value="1000"/>Our $1,000 Package @ 8.0% Interest<br />
<input type="radio" name="loan" value="5000"/>Our $5,000 Package @ 11.5% Interest<br />
<input type="radio" name="loan" value="10000"/>Our $10,000 Package @ 15.0% Interest<br />
<input type="submit" value="Click Here To Submit Loan Applicaton" />
<input type="reset" value="Click Here To Reset" />
 
<?php
$salaryall=$salary/5;
$ageall=($age/10 - ($age%10)/10)-1;
$loanall=$ageall * $salaryall;
print "<br><br><b>Loan Wanted:</b>$loan";
print "<br><br><b>Loan Amount We Will Allow U:</b>$loanall<br><br>";
 
if ($loan <= $loanall)
print "Congrates. $fname $lname, We r delighted to offer u loan";
 
if ($loan > $loanall)
print "Sorry $fname $lname, We cannt offer u loan at this time";
 
 
 
?>
</form>
</body>
 
</html>
 

Re: Plz Help regarding simple coding

Posted: Tue Feb 24, 2009 1:16 am
by susrisha
1. Your php code is embedded into the form.
2. You need to write the PHP code in the file which is presented in the ACTION tag of the form(here its loan.php)
3. You have to get the variables as $salary=$_POST['salary'] . It will not be available directly in the page itself
4. Specify the method in the form tag

Code: Select all

 
<form action="loan.php" action="POST">
 
If you dont specify the method, i think only one variable(the first one) of the form will be passed.