Както е на снимката (приложена), бих искал неограничен брой редове да се въвеждат наведнъж в датабазата:
PHP:
function dostavka(){
if (isset($_POST["dostavka"])){
$nomer_protokol = secure($_POST['nomer_protokol']);
$dostavchik = secure($_POST['dostavchik']);
$kod = secure($_POST['kod']);
$naimenovanie = secure($_POST['naimenovanie']);
$marka = secure($_POST['marka']);
$edinica = secure($_POST['edinica']);
$kvo = secure($_POST['kvo']);
$edcena = secure($_POST['edcena']);
$krcena = secure($_POST['krcena']);
$regtime = date('Y-m-d H:i:s');
$protokol_check = mssql_query("SELECT nomer_protokol FROM dostavki WHERE nomer_protokol='$nomer_protokol'");
$protokol_check = mssql_num_rows($protokol_check);
$broiki_check = mssql_query("SELECT * FROM article WHERE article='$kod'");
$broiki = mssql_fetch_array($broiki_check);
$new_broiki = $broiki['stock'] + $kvo;
//if($_POST["kod"] != "" &&
//$_POST["naimenovanie"] != "" &&
//$_POST["marka"] != "" &&
//$_POST["edinica"] != "" &&
//$_POST["kvo"] != "" &&
//$_POST["edcena"] != "" &&
//$_POST["krcena"] != "")
if (empty($dostavchik) || empty($kod) || empty($nomer_protokol) || empty($naimenovanie) || empty($marka) || empty($edinica) || empty($kvo) || empty($edcena) || empty($krcena)) { echo "<br><table class=ranktable align=center width=90% cellpadding=2 cellspacing=2><tr class=head><td><img src=images/~style/cross_circle.png /><font color='red'>Моля попълнете всички полета!</font></fieldset></td></tr></table><br />"; $error=1;}
elseif($protokol_check > 0) { echo "<BR><table class=ranktable align=center width=90% cellpadding=2 cellspacing=2><tr class=head><td><img src=images/~style/cross_circle.png />Протокол с номер: <font color=red>$nomer_protokol</font> вече съществува!</fieldset></td></tr></table><br />"; $error=1;}
if ($error!=1){
$a = mssql_query("INSERT INTO dostavki (nomer_protokol,dostavchik, kod, naimenovanie, marka, edinica, kvo, edcena, krcena,data)
VALUES ('$nomer_protokol','$dostavchik','$kod','$naimenovanie','$marka','$edinica','$kvo','$edcena','$krcena','$regtime')");
$b = mssql_query("UPDATE article set [stock]='$new_broiki' WHERE article ='$kod'");
echo "<BR><table class=ranktable align=center width=90% cellpadding=2 cellspacing=2><tr class=head><td><img src=images/~style/tick_circle.png />Постъпление с номер: <font color='#39b44a'>$nomer_protokol</font> беше въведенo успешно!</fieldset></td></tr></table><br />";
}
}}
JavaScript:
<script type="text/javascript">
$(document).ready(function(){
var rows = 1;
$("#createRows").click(function(){
var tr = "<tr>";
tr = tr + "<td><input type='text' name='kod' id='kod' size='15'></td>";
tr = tr + "<td><input type='text' name='naimenovanie' id='naimenovanie' size='25'></td>";
tr = tr + "<td><input type='text' name='marka' id='marka' size='10'></td>";
tr = tr + "<td><input type='text' name='edinica' id='edinica' size='2'></td>";
tr = tr + "<td><input type='number' name='kvo' id='kvo' size='3'></td>";
tr = tr + "<td><input type='text' name='edcena' id='edcena' size='3'></td>";
tr = tr + "<td><input type='text' name='krcena' id='krcena' size='3'></td>";
tr = tr + "</tr>";
$('#myTable > tbody:last').append(tr);
//"+rows+"
$('#dostavka').val(rows);
rows = rows + 1;
});
$("#deleteRows").click(function(){
if ($("#myTable tr").length != 1) {
$("#myTable tr:last").remove();
}
});
$("#clearRows").click(function(){
rows = 1;
$('#dostavka').val(rows);
$('#myTable > tbody:last').empty(); // remove all
});
});
</script>