I am making an online banking application, I have used a while loop to print out a dynamic table with information that I will use to make a transaction. I have a dynamic drop down list which supposed to select an account from which to transfer money from but it can only pick the last one...(loop problem), then I have dynamic checkboxes where upon clicking them...here is the code...
<?php
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function tranInfo(){
if (document.account.elements[1].checked == true){
document.account.Total.value = document.account.amount.value;
document.account.TranAmount.value = document.account.amount.value;
}
else{
document.account.Total.value="";
document.account.TranAmount.value = "";
}
}
</script>
</head>
<body>
<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
$dbc = @mysql_connect("localhost", "user553", "bankafrica") or die("Cannot connect to DB!"); // where the database is located, its username and password
mysql_select_db("db553") or die("Cannot select DB!"); //database's name
?>
<form action="Transaction.php" method="post" name="account"> <p>
<label><b>Transfer From Account</b></label>
<p>
<select name="Account" size = "" >
<option value ="">Please select an account to transfer from</option>
<?php
session_start();
$username = $_SESSION['username'];
$query = "SELECT a.AccountNumber,a.AccountType, a.Balance, c.AccountName FROM account a,client c WHERE Username = '$username' AND a.AccountName = c.AccountName";
$r = mysql_query($query);
if(mysql_num_rows($r)){
while($row = mysql_fetch_array($r)){
//$SESSION['AccountName'] = $row['AccountName'];
$account= $row[AccountNumber];
$SESSION['AccountNumber'] = $account;
$iniBalance= $row[Balance];
$SESSION['Balance'] = $iniBalance;
print("<option value=\" $row[AccountNumber],$row[AccountType], $row[Balance]\">AccNo: $account, $row[AccountType], $$row[Balance]</option>");
}
}else{
print("<option value=\"\">No accounts created yet</option>");
}
?>
</select>
<?php //print '<p><h3>Welcome to Bank Africa Online '.$SESSION['username'].
//' You are logged in at' .$SESSION['AccountNumber'].'</h3></p>';
?>
</p>
<hr>
<?php
print("<table width= 900 border= 0 > <tr>
<td width= 62 bgcolor= '#3399FF'> </td>
<td width= 230 bgcolor= '#3399FF' >
<div align= center ><strong>Transaction Account Name</strong></div></td>
<td width= 245 bgcolor= '#3399FF'> <div align= center ><strong>Transaction Account Number </strong></div></td>
<td width= 150 bgcolor= '#3399FF' >
<div align= center ><strong>Bank Name</strong></div></td>
<td width= 115 bgcolor= '#3399FF' ><div align= center ><strong>Amount $ </strong></div></td>
<td width= 180 bgcolor= '#3399FF' ><div align= center ><strong>Narration for Payee </strong></div></td>
</tr>");
$query2 = "SELECT a.AccountNumber,c.AccountName,f.TransactionAccountNumber, f.TranAccName, f.BankName FROM account a,client c, frequentaccount f WHERE Username = '$username' AND a.AccountName = c.AccountName AND a.AccountNumber = f.AccountNumber";
$r = mysql_query($query2);
if(mysql_num_rows($r)){
$i=0;
while($row = mysql_fetch_array($r)){
$TranAccNo = $row[TransactionAccountNumber] ;
$TName =$row[TranAccName];
$BName = $row[BankName];
if($color == "#FFFFFF"){
$color = "#99FFCC";
}else{
$color = "#FFFFFF";
}
$i++;
print("<tr>
<td align= center bgcolor = $color ><input type= checkbox name= record$i value= $TranAccNo onclick= 'tranInfo();' ></td>
<td bgcolor =$color >$row[TranAccName] </td>
<td bgcolor =$color >$row[TransactionAccountNumber]</td>
<td bgcolor =$color >$row[BankName]</td>
<td bgcolor =$color >
<div align= center >
<input name= amount type= text value=0.00 maxlength= 13 width= 100 >
</div></td>
<td bgcolor =$color ><div align= center >
<input name= narration type= text value ='' maxlength= 20 width=100 >
</div></td>
</tr>");
}
}else{
print ("<tr>
<td> </td>
<td>No transaction accounts added</td>
<td> </td>
<td> </td>
<td> </td>
</tr>");
}
print("</table>");
//print"$TranAccNo";
print "<input type=\"hidden\" name=\"trans\" value=\"$i\"/>\n";
if(isset($_POST['submit'])=='submitted')
{
for($i=1;$i<=$_POST['trans'];$i++){
if(isset($_POST["record$i"])){
//print"$account<p>";
$Balance =$iniBalance - $_POST['TranAmount'];
print"$Balance";
//print $_POST["record$i"]."is checked.</br>";
}
}
}
if(isset($POST['submit'])=='submitted')
{
$record= $POST['record'];
for($i=0; $i<count($record); $i++)
{
$remove = $record[$i];
mysql_query("DELETE FROM frequentaccount WHERE TransactionAccountNumber ='$remove'");
print"<META http-equiv= refresh content= 0 URL= Transaction.php</a>";
}
}else{
}
?>
<?php
print"<p> </p>
<table width=887 height=106 border=0>
<tr>
<td width=532 height=102><a href ='updateAccount2.php'>Update Transaction Account>></a>
<p><a href ='addAccount.php'>Add Transaction Account>>></a> </p>
<p>
<a href ='deleteAccount.php'> 'Delete' Transaction Account>></a>
</p> </td>
<td width=345><p>
<p> Total
<input name=Total type=text >
<p> </p></td>
</tr>
</table>";
?>
<hr>
<p>
<?php
if(isset($POST['sumit'])=='submitted')
{
print"$account";
$Balance =$iniBalance- $POST['TranAmount'];
print"$Balance";
}else{
print"no transfers";
}
?>
<form name="performTrans" method="post" action="Transaction.php">
<?php
/*
{
$amount=$_POST['amount'];
$Total= array_sum($amount);
$Transfer=$Total;
}else{
$amount= 0.00;
$Total = $Amount;
$TranAmount = $Total;
}*/
mysql_close();
?>
<p>Transfer Amount
<input name="TranAmount" type="text" value="0.00">
</p>
<p>Transfer Schedule
<input name="radiobutton" type="radio" value="radiobutton">
Today or
<input name="radiobutton" type="radio" value="radiobutton">
Transfer funds on
<select name="select">
<option>Day</option>
</select>
/
<select name="select2">
<option>Month</option>
</select>
</p>
<hr>
<p>
<input type="submit" name="submit" value="Transfer Funds">
</p>
</form>
</form>
<p> </p>
</body>
</html>
<?php
ob_end_flush();
?>