我正在构建一个带有自动计算的系统**
我需要一个建议或回答如何获取文本框的值(totalmiscexpense ,, totalexpenses,totalinc)并将其传递给PHP,以便我可以在我的数据库中启动UPDATE查询
我已尝试过下面的代码,但有时文本框的值变为“未定义”,我无法获得我想要的输出请帮助!
以下是名为 edit_record.php
的表单代码<script>
$(document).ready(function() {
$("#update").click(function() {
var totalmiscexpenses = $('#totalmiscexpense').val();
var totalexpenses = $('#totalexpenses').val();
var totalinc = $('#totalinc').val();
var recdate = $('#recdate').val();
var bill = $('#bill').val();
var disp = $('#disp').val();
var broker = $('#broker').val();
var headown = $('#headown').val();
var plateno = $('#plateno').val();
var consize = $('#consize').val();
var conweight = $('#conweight').val();
var desonefrom = $('#desonefrom').val();
var desoneto = $('#desoneto').val();
var destwofrom = $('#destwofrom').val();
var destwoto = $('#destwoto').val();
var gpreone = $('#gpreone').val();
var gpretwo = $('#gpretwo').val();
var dieselone = $('#dieselone').val();
var disoneam = $('#disoneam').val();
var dieseltwo = $('#dieseltwo').val();
var distwoam = $('#distwoam').val();
var togateone = $('#togateone').val();
var togateam = $('#togateam').val();
var togatewo = $('#togatewo').val();
var togatwoam = $('#togatwoam').val();
var expones = $('#expones').val();
var exponeam = $('#exponeam').val()
var exptwos = $('#exptwos').val();
var exptwoam = $('#exptwoam').val();
var exptree = $('#exptree').val();
var exptream = $('#exptream').val();
var expfors = $('#expfors').val();
var expforam = $('#expforam').val();
var expfives = $('#expfives').val();
var expfiveam = $('#expfiveam').val();
var expsixs = $('#expsixs').val();
var expsixam = $('#expsixam').val();
var expsevs = $('#expsevs').val();
var expsevam = $('#expsevam').val();
var expeyts = $('#expeyts').val();
var expeytam = $('#expeytam').val();
var expnines = $('#expnines').val();
var expnineam = $('#expnineam').val();
var exptens = $('#exptens').val();
var exptenam = $('#exptenam').val();
var expelevs = $('#expelevs').val();
var expelevam = $('#expelevam').val();
var drivername = $('#drivername').val();
var driversal = $('#driversal').val();
var helpname = $('#helpname').val();
var helpsal = $('#helpsal').val();
var income = $('#income').val();
var datas = 'totalmiscexpenses=' + totalmiscexpenses + '&totalexpenses=' + totalexpenses + '&totalinc=' + totalinc + '&recdate=' + recdate + '&bill=' + bill + '&disp=' + disp + '&broker=' + broker + '&headown=' + headown + '&plateno=' + plateno + '&consize=' + consize + '&conweight=' + conweight + '&desonefrom=' + desonefrom + '&desoneto=' + desoneto + '&destwofrom=' + destwofrom + '&destwoto=' + destwoto + '&gpreone=' + gpreone + '&gpretwo=' + gpretwo + '&dieselone=' + dieselone + '&disoneam=' + disoneam + '&dieseltwo=' + dieseltwo + '&distwoam=' + distwoam + '&togateone=' + togateone + '&togateam=' + togateam + '&togatewo=' + togatewo + '&togatwoam=' + togatwoam + '&expones=' + expones + '&exponeam=' + exponeam + '&exptwos=' + exptwos + '&exptwoam=' + exptwoam + '&exptree=' + exptree + '&exptream=' + exptream + '&expfors=' + expfors + '&expforam=' + expforam + '&expfives=' + expfives + '&expfiveam=' + expfiveam + '&expsixs=' + expsixs + '&expsixam=' + expsixam + '&expsevs=' + expsevs + '&expsevam=' + expsevam + '&expeyts=' + expeyts + '&expeytam=' + expeytam + '&expnines=' + expnines + '&expnineam=' + expnineam + '&exptens=' + exptens + '&exptenam=' + exptenam + '&expelevs=' + expelevs + '&expelevam=' + expelevam + '&drivername=' + drivername + '&driversal=' + driversal + '&helpname=' + helpname + '&helpsal=' + helpsal + '&income=' + income;
$.ajax({
type: "POST",
url: "updaterecord.php",
dataType: "json",
data: datas,
success: function() {
window.location('record_list.php');
}
});
});
});
</script>
<?php
$query=mysql_query("select * from tbl_records where id='$ID'")or die(mysql_error());
$row=mysql_fetch_array($query);
?>
<form method="post" id="entryVal" enctype="multipart/form-data" class="">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label> Record ID </label>
<input type="number" name="ID" value="<?php echo $row['id']; ?>" class="form-control"
placeholder="test" disabled/>
</div>
<div class="form-group">
<label> Date Encoded </label>
<input type="text" name="recdate" value="<?php echo $row['recdate']; ?>" class="form-control"
placeholder="Date" disabled/>
</div>
<div class="form-group">
<label> Date Recorded </label>
<input type="date" name="recdate" value="<?php echo $row['date']; ?>" class="form-control"
placeholder="Date"/>
</div>
<div class="form-group">
<label> Way Bill No.</label>
<input type="text" name="bill" value="<?php echo $row['billNum']; ?>" class="form-control" placeholder="Bill number" />
</div>
<div class="form-group">
<label> Dispatcher </label>
<input type="text" name="disp" value="<?php echo $row['disPatcher']; ?>" class="form-control" placeholder="Mr. / Mrs. " />
</div>
<div class="form-group">
<label> Broker </label>
<input type="text" name="broker" value="<?php echo $row['broKer']; ?>" class="form-control" placeholder="Mr. / Mrs." />
</div>
<div class="form-group">
<label > Tractor Head Owner </label>
<input type="text" name="headown" value="<?php echo $row['hOwner']; ?>"class="form-control" placeholder="test" />
</div>
<div class="form-group">
<label> Plate Number </label>
<input type="text" name="plateno" value="<?php echo $row['pNumb']; ?>" class="form-control" placeholder="test" />
</div>
<div class="form-group">
<label> Container Size </label>
<input type="text" name="consize" value="<?php echo $row['conSize']; ?>" class="form-control" placeholder="test" />
</div>
<div class="form-group">
<label> Container Gross Weight </label>
<input type="text" name="conweight" value="<?php echo $row['grossWeight']; ?>" class="form-control" placeholder="test" />
</div>
<div class="form-group">
<label> Destination 1 </label>
<div class="form-inline">
<input type="text" name="desonefrom" value="<?php echo $row['desoneFrom']; ?>" class="form-control"placeholder="From" style="width:49%">
<input type="text" name="desoneto" value="<?php echo $row['desoneTo']; ?>" class="form-control" placeholder="To" style="width:49%">
</div>
</div>
<div class="form-group">
<label> Destination 2 </label>
<div class="form-inline">
<input type="text" name="destwofrom" value="<?php echo $row['destwoFrom']; ?>" class="form-control" placeholder="From" style="width:49%">
<input type="text" name="destwoto" value="<?php echo $row['destwoTo']; ?>" class="form-control" placeholder="To" style="width:49%">
</div>
</div>
<div class="form-group">
<label> Gross Preight 1 </label>
<input type="text" value="<?php echo $row['grossPreone']; ?>" class="form-control" placeholder="From" name="gpreone">
</div>
<div class="form-group">
<label> Gross Preight 2 </label>
<input type="text" value="<?php echo $row['grossPretwo']; ?>" class="form-control" placeholder="From" name="gpretwo">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<h4> Less:
<button id="showM"type="button" class="btn-sm btn-primary" aria-label="Left Align">
<span class="glyphicon glyphicon-plus" aria-hidden="true"> </span> Show more
</button>
<button id="showL"type="button" class="btn-sm btn-primary" aria-label="Left Align">
<span class="glyphicon glyphicon-minus" aria-hidden="true"> </span> Show less
</button>
</h4>
</div>
<div id="less">
<div class="form-group">
<label> Diesel 1 </label>
<div class="form-inline">
<input type="text" name="dieselone" class="form-control" value="<?php echo $row['dieselOne']; ?>" placeholder="What diesel" style="width:49%">
<input type="text" value="<?php echo $row['dieseOnelAm']; ?>" id="diesel1" name="disoneam" class="form-control" placeholder="Price" style="width:49%">
</div>
</div>
<div class="form-group">
<label> Diesel 2 </label>
<div class="form-inline">
<input type="text" name="dieseltwo" value="<?php echo $row['dieselTwo']; ?>" class="form-control" placeholder="What diesel" style="width:49%">
<input type="text" value="<?php echo $row['dieselTwoAm']; ?>" id="diesel2" name="distwoam" class="form-control" placeholder="Price" style="width:49%">
</div>
</div>
<div class="form-group">
<label> Toll Gate 1 </label>
<div class="form-inline">
<input type="text" name="togateone" value="<?php echo $row['tolloneFrom']; ?>" class="form-control" placeholder="Toll from" style="width:49%">
<input type="text" value="<?php echo $row['tolloneAm']; ?>" id="tollone" name="togateam" class="form-control" placeholder="Price" style="width:49%">
</div>
</div>
<div class="form-group">
<label> Toll Gate 2 </label>
<div class="form-inline">
<input type="text" value="<?php echo $row['tolltwoFrom']; ?>" name="togatetwo" class="form-control" placeholder="Toll from" style="width:49%">
<input type="text" id="tolltwo" name="togatwoam" value="<?php echo $row['tolltwoAm']; ?>" class="form-control" placeholder="Price" style="width:49%">
</div>
</div>
<div class="form-group">
<div class="Form-inline">
<label> Miscellanaous expenses: </label>
<button id="miscShw"type="button" class="btn-sm btn-primary" aria-label="Left Align">
<span class="glyphicon glyphicon-plus" aria-hidden="true"> </span> Add
</button>
<button id="miscLss"type="button" class="btn-sm btn-danger" aria-label="Left Align">
<span class="glyphicon glyphicon-minus" aria-hidden="true"> </span>
Delete
</button>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<input type="text" value="<?php echo $row['exOne']; ?>" name="expone" class="form-control" placeholder="Expenses" style="width:49%">
<input type="text" id="expone" name="exponeam" value="<?php echo $row['exOneam']; ?>" class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<input type="text"name="exptwo" value="<?php echo $row['exTwo']; ?>"class="form-control" placeholder="expenses"style="width:49%">
<input type="text" id="exptwo" name="exptwoam" value="<?php echo $row['exTwoam']; ?>" class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<input type="text" value="<?php echo $row['exThree']; ?>" name="exptre" class="form-control" placeholder="expenses"style="width:49%">
<input type="text" id="exptre" name="exptream" value="<?php echo $row['exThreeam']; ?>" class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<input type="text" name="expfor" value="<?php echo $row['exFour']; ?>" class="form-control" placeholder="expenses"style="width:49%">
<input type="text" id="expfor" name="expforam" value="<?php echo $row['exFouram']; ?>"class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<input type="text" name="expfive" value="<?php echo $row['exFive']; ?>" class="form-control" placeholder="expenses"style="width:49%">
<input type="text" value="<?php echo $row['exFiveam']; ?>" id="expfive" name="expfiveam" class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div id="6" class="form-inline">
<input type="text" name="expsix" value="<?php echo $row['exSix']; ?>" class="form-control" placeholder="expenses"style="width:49%">
<input type="text" id="expsix" value="<?php echo $row['exSixam']; ?>"name="expsixam" class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div id="7" class="form-inline">
<input type="text" name="expsev" value="<?php echo $row['exSeven']; ?>"class="form-control" placeholder="expenses"style="width:49%">
<input type="text" id="expsev" value="<?php echo $row['exSevenam']; ?>"name="expsevam" class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div id="8" class="form-inline">
<input type="text" name="expeyt" value="<?php echo $row['exEight']; ?>" class="form-control" placeholder="expenses"style="width:49%">
<input type="text" id="expeyt" name="expeytam" value="<?php echo $row['exEightam']; ?>"class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div id="9" class="form-inline">
<input type="text" name="expnine" value="<?php echo $row['exNine']; ?>"class="form-control" placeholder="expenses"style="width:49%">
<input type="text" id="expnine" name="expnineam" value="<?php echo $row['exNineam']; ?>"class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div id="10" class="form-inline">
<input type="text" name="expten" value="<?php echo $row['exTen']; ?>"class="form-control" placeholder="expenses"style="width:49%">
<input type="text" id="expten" name="exptenam" value="<?php echo $row['exTenam']; ?>"class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<div id="11" class="form-inline">
<input type="text" name="expelev" value="<?php echo $row['exElev']; ?>"class="form-control" placeholder="expenses"style="width:49%">
<input type="text" id="expelev" name="expelevam" value="<?php echo $row['exElevam']; ?>" class="form-control" placeholder="Price"style="width:49%">
</div>
</div>
<div class="form-group">
<label class="red"> Total Misc. Expenses* </label>
<input type="text" id="totalmiscexpense" name="totalmisc" value="<?php echo $row['totalMisc']; ?>"class="form-control" placeholder="Amount" disabled>
</div>
<div class="form-group">
<label> Driver </label>
<div class="form-inline">
<input type="text" name="drivername" value="<?php echo $row['driverName']; ?>"class="form-control" placeholder="Name" style="width:49%;">
<input type="text" name="drivsal" value="<?php echo $row['driverSal']; ?>"class="form-control" placeholder="Salary" id="driversal" style="width:49%;">
</div>
</div>
<div class="form-group">
<label> Helper </label>
<div class="form-inline">
<input type="text" name="helpname" value="<?php echo $row['helpName']; ?>" class="form-control" placeholder="Amount" style="width:49%;">
<input type="text" name="helpsal" value="<?php echo $row['helpSal']; ?>"class="form-control" placeholder="Salary" id="helpsal" style="width:49%;">
</div>
</div>
<div class="form-group">
<label class="red"> Total Expenses* </label>
<input type="text" id="totalexpenses" name="totalexpense" value="<?php echo $row['totalExpense']; ?>"class="form-control" placeholder="Salary" disabled/>
</div>
<div class="form-group">
<label> NET Income </label>
<input type="text" id="income" name="netincome" value="<?php echo $row['income']; ?>"class="form-control" placeholder="Amount">
</div>
<div class="form-group">
<label class="red"> Total Income* </label>
<input type="text" id="totalinc" name="totalinc" value="<?php echo $row['totalincome']; ?>"class="form-control" placeholder="Amount" disabled/>
</div>
</div>
</div>
</div>
<div class="form-group center">
<button type="submit" name="update" id="update" class="btn btn-success"><i class="glyphicon glyphicon-check"></i> Update</button>
</div>
</form>
以下是updaterecord.php的代码
<?php
include('include/database.php');
include('session.php');
$id=$_GET['id'];
$_POST = stripslashes_deep($_POST);
$recdate=$_POST['recdate'];
$bill=$_POST['bill'];
$disp=$_POST['disp'];
$broker=$_POST['broker'];
$headown=$_POST['headown'];
$plateno=$_POST['plateno'];
$consize=$_POST['consize'];
$conweight=$_POST['conweight'];
$desonefrom=$_POST['desonefrom'];
$desoneto=$_POST['desoneto'];
$destwofrom=$_POST['destwofrom'];
$destwoto=$_POST['destwoto'];
$gpreone=$_POST['gpreone'];
$gpretwo=$_POST['gpretwo'];
$dieselone=$_POST['dieselone'];
$disoneam=$_POST['disoneam'];
$dieseltwo=$_POST['dieseltwo'];
$distwoam=$_POST['distwoam'];
$togateone=$_POST['togateone'];
$togateam=$_POST['togateam'];
$togatewo=$_POST['togatewo'];
$togatwoam=$_POST['togatwoam'];
$expones=$_POST['expones'];
$exponeam=$_POST['exponeam'];
$exptwos=$_POST['exptwos'];
$exptwoam=$_POST['exptwoam'];
$exptree=$_POST['exptree'];
$exptream=$_POST['exptream'];
$expfors=$_POST['expfors'];
$expforam=$_POST['expforam'];
$expfives=$_POST['expfives'];
$expfiveam=$_POST['expfiveam'];
$expsixs=$_POST['expsixs'];
$expsixam=$_POST['expsixam'];
$expsevs=$_POST['expsevs'];
$expsevam=$_POST['expsevam'];
$expeyts=$_POST['expeyts'];
$expeytam=$_POST['expeytam'];
$expnines=$_POST['expnines'];
$expnineam=$_POST['expnineam'];
$exptens=$_POST['exptens'];
$exptenam=$_POST['exptenam'];
$expelevs=$_POST['expelevs'];
$expelevam=$_POST['expelevam'];
$income=$_POST['income'];
$drivername=$_POST['drivername'];
$driversal=$_POST['driversal'];
$helpname=$_POST['helpname'];
$helpsal=$_POST['helpsal'];
$totalmiscexpenses = $_POST['totalmiscexpenses'];
$totalexpenses = $_POST['totalexpenses'];
$totalinc = $_POST['totalinc'];
//audit trail
$history_record=mysql_query("SELECT * from user where user_id=$id_session");
$row=mysql_fetch_array($history_record);
$user=$row['firstname']." ".$row['lastname'];
mysql_query("INSERT INTO history (date,action,data) VALUES (NOW(),'New Record','$user')")or die(mysql_error());
//query for records
$queryupdate= mysql_query ("UPDATE tbl_records SET billNum='$bill',disPatcher='$disp',broKer='$broker',hOwner='$headown',pNumb='$plateno',conSize='$consize',grossWeight='$conweight',desoneFrom='$desonefrom',desoneTo='$desoneto',destwoFrom='$destwofrom', destwoTo='$destwoto',grossPreone='$gpreone',grossPretwo='$gpretwo',dieselOne='$dieselone',dieseOnelAm='$disoneam',dieselTwo='$dieseltwo',dieselTwoAm='$distwoam',tolloneFrom='$togateone',tolloneAm='$togateam',tolltwoFrom='$togatewo',tolltwoAm='$togatwoam',exOne='$expones',exOneam='$exponeam',exTwo='$exptwos',exTwoam='$exptwoam',exThree='$exptree',exThreeam='$exptream',exFour='$expfors',exFouram='$expforam',exFive='$expfives',exFiveam='$expfiveam',exSix='$expsixs',exSixam='$expsixam',exSeven='$expsevs',exSevenam='$expsevam',exEight='$expeyts',exEightam='$expeytam',exNine='$expnines',exNineam='$expnineam',exTen='$exptens',exTenam='$exptenam',exElev='$expelevs',exElevam='$expelevam',totalMisc='$totalmiscexpenses',driverName='$drivername',driverSal='$driversal',helpName='$helpname',helpSal='$helpsal',totalExpense='$totalexpenses',income='$income',totalincome='$totalinc',date='$recdate',recdate= '$dt' WHERE id='$id'")or die('Failed');
if($queryupdate){
echo "<script>alert('Record added.'); window.location='record_list.php'</script>";
}
?>
答案 0 :(得分:0)
尝试使用$(&#39;#entryVal&#39;)。序列化()类似数据:$(&#39;#entryVal&#39;)。serialize()
答案 1 :(得分:0)
使这个ajax脚本变得简单
def urlFile = { url, name ->
File file = new File("$buildDir/download/${name}.jar")
file.parentFile.mkdirs()
if (!file.exists()) {
new URL(url).withInputStream { downloadStream ->
file.withOutputStream { fileOut ->
fileOut << downloadStream
}
}
}
files(file.absolutePath)
}
dependencies { //example
compile urlFile('https://github.com/java-native-access/jna/blob/4.2.2/lib/native/android-arm.jar?raw=true', 'jna-android-arm')
}