0

Hi .. i need some help here .. i'm a 3rd year student of computer science .. and i'm pretty new to these stuffs ..

my problem is i have to validate the the checkbox and i have to make computations from it ..
here's the code :

<h1><center>LOAN AMOUNT</center></h1>
<br>

<table align="center">

<tr>
<td>Select Loan Amount :</td></tr>

<tr><td><input type="radio" name="loan" value="PHP 5,000.00">PHP 5,000.00</td></tr>
<tr><td><input type="radio" name="loan" value="PHP 10,000.00">PHP 10,000.00</td></tr>
<tr><td><input type="radio" name="loan" value="PHP 15,000.00">PHP 15,000.00</td></tr>
<tr><td><input type="radio" name="loan" value="PHP 20,000.00">PHP 20,000.00</td></tr>
<tr><td><input type="radio" name="loan" value="PHP 25,000.00">PHP 25,000.00</td></tr>

<tr>
<td>Terms of Payment : </td>
</tr>

<tr>
<td><input type="radio" name="pay" value="6 mos.">6 mos.
<input type="radio" name="pay" value="12 mos.">12 mos.
<input type="radio" name="pay" value="24 mos.">24 mos.</td>
</tr>

<tr>
<td>Cooperative Officer : </td>
</tr>

<tr>
<td><input type="checkbox" name="CO" value="Yes">Yes</td>
</tr>

</table>
<br>
<br>
<center>
<input type="submit" name="pass" value="Confirm Loan">
<input type="reset" value="Clear All">
</center>

when the checkbox of "CO" was clicked .. i have to get the interest(5%) of loan amount .. and when it wasn't clicked .. i have to get the interest(10%) of loan amount ..
then i have to show the interest and the original loan amount on the next page .. i'm not pretty sure where do i have to put the computation of this .. so please .. i need help ..

THX in ADVANCE

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by epixeltechno
0

I don't see the form tag but I assume you are using post method:

$loan = str_replace('PHP ','',$_POST['loan']);

if($_POST['CO'] == 'Yes')
{
    # 5% computation
    $interest = $loan * 0.05;
}

else
{
   # 10% computation
   $interest = $loan * 0.1;
}

echo 'loan: '. $loan;
echo 'interest: '. $interest;

Side note, you can reduce the conditional statement to this:

$interest = ($_POST['CO'] == 'Yes') ? $loan * 0.05 : $loan * 0.1;

bye :)

Edited by cereal: n/a

0

As you are new to PHP I suggest you always test what is in your input variables to get a better understanding why it is done that way.

var_dump($_POST['loan'],$_POST['CO']);

Read more about checkboxes, radio buttons, input fields and how they are presented at run time.
It is better for you that way instead someone solves your task for you.

Edited by fenixZ: n/a

0

I've figured it out on how to execute the computation .. i've changed the value of the loan amounts and eliminate the 'PHP' and '.00' .. because it's returning '0' when it is present in the value ..

now my new problem is how to show the values in "PHP xx,000.00" format .. any idea guys ? ..

Edited by mukororokudo: n/a

-1

1.
<form method="POST" name="myform2" action="<?php echo $_SERVER; ?>">
2.
<br>
3.
Please enter a UserID to update with award icons:<br>
4.
UserID: <input type="text" name="multiid"> <br>
5.
<br>
6.
Attack <input type="checkbox" onClick="document.myform2.a0.value = this.checked"><
7.
Defence <input type="checkbox" onClick="document.myform2.b0.value = this.checked"><br>
8.
<input type="hidden" name="b0" value="3">
9.
Strength <input type="checkbox" onClick="document.myform2.c0.value = this.checked"><br>
10.
<input type="hidden" name="c0" value="13">
11.
HP <input type="checkbox" onClick="document.myform2.d0.value = this.checked"> <br>
12.
<input type="hidden" name="d0" value="11">
13.
Ranged <input type="checkbox" onClick="document.myform2.e0.value = this.checked"> <br>
14.
<input type="hidden" name="e0" value="16">
15.
Prayer <input type="checkbox" onClick="document.myform2.f0.value = this.checked"> <br>
16.
<input type="hidden" name="f0" value="19">
17.
Magic <input type="checkbox" onClick="document.myform2.g0.value = this.checked"> <br>
18.
<input type="hidden" name="g0" value="12">
19.
Cooking <input type="checkbox" onClick="document.myform2.h0.value = this.checked"> <br>
20.
<input type="hidden" name="h0" value="1">
21.
Woodcutting <input type="checkbox" onClick="document.myform2.i0.value = this.checked"> <br>
22.
<input type="hidden" name="i0" value="21">
23.
Fletching <input type="checkbox" onClick="document.myform2.j0.value = this.checked"> <br>
24.
<input type="hidden" name="j0" value="4">
25.
Fishing <input type="checkbox" onClick="document.myform2.k0.value = this.checked"> <br>
26.
<input type="hidden" name="k0" value="9">
27.
Firemaking <input type="checkbox" onClick="document.myform2.l0.value = this.checked"> <br>
28.
<input type="hidden" name="l0" value="8">
29.
Crafting <input type="checkbox" onClick="document.myform2.m0.value = this.checked"> <br>
30.
<input type="hidden" name="m0" value="6">
31.
Smithing <input type="checkbox" onClick="document.myform2.n0.value = this.checked"> <br>
32.
<input type="hidden" name="n0" value="15">
33.
Mining <input type="checkbox" onClick="document.myform2.o0.value = this.checked"> <br>
34.
<input type="hidden" name="o0" value="14">
35.
Herblore <input type="checkbox" onClick="document.myform2.p0.value = this.checked"> <br>
36.
<input type="hidden" name="p0" value="10">
37.
Agility <input type="checkbox" onClick="document.myform2.q0.value = this.checked"> <br>
38.
<input type="hidden" name="q0" value="5">
39.
Thieving <input type="checkbox" onClick="document.myform2.r0.value = this.checked"> <br>
40.
<input type="hidden" name="r0" value="20">
41.
Slayer <input type="checkbox" onClick="document.myform2.s0.value = this.checked"> <br>
42.
<input type="hidden" name="s0" value="18">
43.
Farming <input type="checkbox" onClick="document.myform2.t0.value = this.checked"> <br>
44.
<input type="hidden" name="t0" value="7">
45.
Runecraft <input type="checkbox" onClick="document.myform2.u0.value = this.checked"> <br>
46.
<input type="hidden" name="u0" value="17">
47.
Hunter <input type="checkbox" onClick="document.myform2.v0.value = this.checked"> <br>
48.
<input type="hidden" name="v0" value="47">
49.
Construction <input type="checkbox" onClick="document.myform2.w0.value = this.checked"> <br>
50.
<input type="hidden" name="w0" value="50">
51.
<br><br>
52.
<input type="submit" name="Submit"> </form>
53.

54.

55.
<?
56.
$attack80 = $_POST;
57.
$defence80 = $_POST;
58.
$strength80 = $_POST;
59.
$hp80 = $_POST;
60.
$ranged80 = $_POST;
61.
$prayer80 = $_POST;
62.
$magic80 = $_POST;
63.
$cooking80 = $_POST;
64.
$woodcutting80 = $_POST;
65.
$fletching80 = $_POST;
66.
$fishing80 = $_POST;
67.
$firemaking80 = $_POST;
68.
$crafting80 = $_POST;
69.
$smithing80 = $_POST;
70.
$mining80 = $_POST;
71.
$herblore80 = $_POST;
72.
$agility80 = $_POST;
73.
$thieving80 = $_POST;
74.
$slayer80 = $_POST;
75.
$farming80 = $_POST;
76.
$runecraft80 = $_POST;
77.
$hunter80 = $_POST;
78.
$construction80 = $_POST;
79.

80.
$multiid = $_POST;
81.

82.
if ($multiid = '')
83.
{
84.
echo "Please enter an userid";
85.
}
86.

87.

88.
else
89.
{
90.

91.
if ($attack80 = '2')
92.
{
93.
echo "Yes this works";
94.
$db->query_write("
95.
INSERT INTO " . TABLE_PREFIX . "award_user
96.
(award_id, userid, issue_reason, issue_time)
97.
VALUES ('2', '$multiid', '" . addslashes($vbulletin->GPC) . "', " . time() . ")
98.
");
99.
}
100.

101.
if ($defence80 = '3')
102.
{
103.
$db->query_write("
104.
INSERT INTO " . TABLE_PREFIX . "award_user
105.
(award_id, userid, issue_reason, issue_time)
106.
VALUES ('3', '$multiid', '" . addslashes($vbulletin->GPC) . "', " . time() . ")
107.
");
108.
}
109.

110.
}


that might help you

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.