下面是我的代码,我想把每行的html表数据插入到sql中,但是使用这段代码,只把最后一个trow存储到数据库表中,我想我需要用loop读取每一个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请求发送到服务器。
您可以从
这里https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started
或者可以选择使用JQuery之类的JavaScript库来帮助您满足AJAX需求。
http://api.jquery.com/jquery.ajax/
也可以在表中使用HTML输入提交所有值,但不建议这样做。
关于php - 如何将每个tr的HTML表数据插入到SQL表中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36638327/