主页
<!doctype html>
<?php
include 'db_connect.php';
session_start();
if(!isset($_SESSION['myusername']))
header("location:main_login.php");
?>
<html>
<head>
<script>
function show(){
document.getElementById("cheque").value="";
}
function hide(){
document.getElementById("cheque").value="Cash";
}
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_edit_payment.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body style="text-align: center">
<form name="add_payment" method="post" action="add_payment.php">
<label for="select"><span style="text-align: center">Select Client:</span></label>
<span style="text-align: center">
<select name="client_name" id="select" onChange="showUser(this.value)";>
<option value="">Select:</option>
<?php
$sql = mysql_query("SELECT name FROM client");
while ($row = mysql_fetch_array($sql)){
echo "<option value=\"".$row['name']."\">".$row['name']."</option>";
}
?>
</select>
<div id="txtHint"></div><br>
<label for="select"><span style="text-align: center">Financial Year:</span></label>
<select name="fy" id="fy" >
<option value="2005-06">2005-06</option>
<option value="2006-07">2006-07</option>
<option value="2007-08">2007-08</option>
<option value="2008-09">2008-09</option>
<option value="2009-10">2009-10</option>
<option value="2010-11">2010-11</option>
<option value="2011-12">2011-12</option>
<option value="2012-13">2012-13</option>
<option value="2013-14">2013-14</option>
<option value="2014-15">2014-15</option>
<option value="2015-16">2015-16</option>
<option value="2016-17">2016-17</option>
<option value="2017-18">2017-18</option>
<option value="2018-19">2018-19</option>
<option value="2019-20">2019-20</option>
<option value="2020-21">2020-21</option>
</select>
<label for="date">Date: </label>
<input name="date" id"date" type="date">
<label for="receiptno"><span style="text-align: right">Receipt no: </span></label>
<input name="receiptno" type="text" id="receiptno">
<br><br>
<label for="amount"> Amount: </label>
<input name="amount" type="text" id="amount">
<label for="received">Received </label>
<input name="received" type="radio" id="received" onClick="hide();" value="Cash" checked>
Cash
<input type="radio" id="received" name="received" value="Cheque" onClick="show();">Cheque
<label for="cheque">Cheque no: </label>
<input name="cheque" value="Cash" type="text" id="cheque"><br><br>
<label for="select">Select Auditor:</label>
<select name="auditor_name" id="select">
<?php
$sql = mysql_query("SELECT name FROM auditors");
while ($row = mysql_fetch_array($sql)){
echo "<option value=\"".$row['name']."\">".$row['name']."</option>";
}
?>
<input type="submit" value="Add">
</form>
<p> </p>
</body>
</html>
它的输出是
ajax_edit_payment.php
<?php
$q = $_GET['q'];
include 'db_connect.php';
$sql="SELECT name,address,mobile,email,pan,tan FROM client WHERE name = '$q'";
$sql_bill="SELECT clientname,financialyear,receiptno,amount,ddate,type,chequeno,category FROM billing WHERE clientname = '$q'";
$sql_total="SELECT SUM(amount) AS TotalAmount FROM billing";
$result = mysql_query($sql);
$result_bill = mysql_query($sql_bill);
$result_total = mysql_query($sql_total);
$total= mysql_fetch_array($result_total);
echo "<h4><b>Client details</b></h4><table align='center' border='2'>
<tr>
<th>Name</th>
<th>Address</th>
<th>Mobile</th>
<th>Email</th>
<th>PAN</th>
<th>VAT TIN</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['mobile'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['pan'] . "</td>";
echo "<td>" . $row['tan'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<h4><b>Payment received details</b></h4><table align='center' border='2'>
<tr>
<th>Client Name</th>
<th>Financial Year</th>
<th>Receipt No</th>
<th>Date</th>
<th>Type</th>
<th>Chequeno</th>
<th>Category</th>
<th>Amount</th>
</tr>";
while($row = mysql_fetch_array($result_bill))
{
echo "<tr >";
echo "<td id=1>" . $row['clientname'] . "</td>";
echo "<td id=2>" . $row['financialyear'] . "</td>";
echo "<td id=3>" . $row['receiptno'] . "</td>";
echo "<td id=4>" . $row['ddate'] . "</td>";
echo "<td id=5>" . $row['type'] . "</td>";
echo "<td id=6>" . $row['chequeno'] . "</td>";
echo "<td id=7>" . $row['category'] . "</td>";
echo "<td id=8>" . $row['amount'] . "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan=7>Total</td>";
echo "<td>".$total['TotalAmount']. "</td>";
echo "</tr>";
echo "</table>";
?>
我正在使用AJAX来获得响应,最终输出是
现在点击表格中的任何一行,我希望使用用户点击的表格行中的值更新所有字段(财务年度,收据编号,金额等)。 建议我更容易做到这一点