这是我的以下代码,我想将每行的html表数据插入到sql中,但是使用此代码,仅将最后的trow存储到数据库表中,我想我需要使用循环读取每个trow的数据,而不仅仅是最后的trow,有任何想法吗?
<?php
//connect
if (isset($_POST['submit'])){
$con = mysql_connect("localhost","Matt","password");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("propereva",$con);
INSERT INTO properevatables (Number, Name,BasicSalary,ServiceMonths,SalaryPercentWithoutCEO,SalaryPercentWithCeo,PercentEvaShareByCeoDirectReports,PercentEvaShareByCeoAndDirectReports,PercentKpi,EvaBonusInMonths,percentwithbank,TotalEvaBonus,totalwithbank) VALUES ('$_POST[number]','$_POST[membername]','$_POST[salary]','$_POST[service]','$_POST[percentwithoutCEO]','$_POST[percentwithCEO]','$_POST[ceoReport]','$_POST[directresult]','$_POST[kpi]','$_POST[resultpercentageEVA]','$_POST[percentwithbank]','$_POST[yearonly]','$_POST[totalwithbank]')";
mysql_query($sql,$con);
mysql_close($con);
}
?>
您要做的是将整个表的数据发送到服务器进行存储。
您可以使用JavaScript进行此操作,并将所有数据整理到JSON对象中,然后使用AJAX请求发送到服务器。
您可以从中了解JavaScript中的AJAX
在这里https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started
或者您可以选择使用JavaScript库(例如JQuery)来满足您的AJAX需求。
http://api.jquery.com/jquery.ajax/
您也可以在表中使用HTML输入来提交所有值,但是不建议这样做。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句