$sql="INSERT INTO sk_".$sklad."_dvizh_arc (type,numd,numdf,docyr,spr_id,quant,ddate,post_id,comment_id,price) VALUES ('0','$numd','$numdf','$docyr','$id','$ost','$ddate','$post_id','$comment_id','0')" ; mylog1($sql); print $sql."<br>"; if(!mysql_query($sql)) my_error(); // создадим первое движение года // коментарий $sql="SELECT id FROM coments WHERE comment='Остаток на 31.12.$docyr'"; print $sql."<br>"; $res1 = mysql_query($sql); if ($rs1=mysql_fetch_array($res1)){ $comment_id = $rs1["id"]; } else { $sql="INSERT INTO coments (comment) VALUES ('Остаток на 31.12.$docyr')"; mylog1($sql); mysql_query($sql); $comment_id = mysql_insert_id(); if (!$comment_id) my_error(); } $docyr = date("Y"); $ddate = date("Y-m-d",mktime(0,0,0,1,1,$docyr)); $sql="INSERT INTO sk_".$sklad."_dvizh (type,numd,numdf,docyr,spr_id,quant,ddate,post_id,comment_id,price) VALUES ('1','$numd','$numdf','$docyr','$id','$ost','$ddate','$post_id','$comment_id','0')" ; mylog1($sql); print $sql."<br>"; if(!mysql_query($sql)) my_error(); } print "<script>window.location='http://".$_SERVER['HTTP_HOST'].$GLOBALS["PHP_SELF"]."';</script>"; ?>
function mysql_query1($sql) { // логирование вставить mylog1($sql); return mysql_query($sql); }