2017-08-29 94 views
0

截图画面更新的行不工作,保存按钮复制行

enter image description here

注意:未定义指数:cur_id1在C:\ Program Files文件 (x86)的\ APACHE2.2 \ htdocs中\ hr \ setup \ manage_position_sub.php on line 87

警告:mssql_query()[function.mssql-query]:message:关键字'and'附近的语法错误 。 (严重性15)在C:\ Program Files (x86)\ Apache2.2 \ htdocs \ hr \ includes \ connecto.php on line 15

警告:mssql_query()[function.mssql-query]:查询失败在 C:\程序文件(x86)\ APACHE2.2 \ htdocs中\小时\包括关于 线\ connecto.php 15

说明:未定义指数:cur_id1在C:\ Program Files文件 (86)\的Apache2 .2 \ htdocs \ hr \ setup \ manage_position_sub.php on line 89

Warning:mssql_query()[function.mssql-query]:message:关键字'and'附近的语法错误 。 (严重性15)在C:\ Program Files (x86)\ Apache2.2 \ htdocs \ hr \ includes \ connecto.php on line 15

警告:mssql_query()[function.mssql-query]:查询失败在 C:\程序文件(x86)\ APACHE2.2 \ htdocs中\小时\包括关于 线\ connecto.php 15

说明:未定义指数:cur_id1在C:\ Program Files文件 (86)\的Apache2 .2在线92上的\ htdocs \ hr \ setup \ manage_position_sub.php

警告:mssql_query()[function.mssql-query]:消息:关键字'and'附近的语法不正确 。 (严重性15)在C:\ Program Files (x86)\ Apache2.2 \ htdocs \ hr \ includes \ connecto.php on line 15

警告:mssql_query()[function.mssql-query]:查询失败在 C:\程序文件(x86)\ APACHE2.2 \ htdocs中\小时\包括关于 线\ connecto.php 15

说明:未定义指数:cur_id1在C:\ Program Files文件 (86)\的Apache2 0.2 \ htdocs中\上线94

小时\设置\ manage_position_sub.php警告:mssql_query()[function.mssql-查询]:消息:关键字 '和' 近不正确 语法。 (严重性15)在C:\ Program Files (x86)\ Apache2.2 \ htdocs \ hr \ includes \ connecto.php on line 15

警告:mssql_query()[function.mssql-query]:查询失败在 C:\程序文件(x86)\ APACHE2.2 \ htdocs中\小时\包括关于 线\ connecto.php 15

说明:未定义指数:cur_id1在C:\ Program Files文件 (86)\的Apache2 .2 \ htdocs \ hr \ setup \ manage_position_sub.php on line 96

现在的问题是,当我点击保存按钮更新查询它只是复制最后一次行。插入时没有问题。 php代码如下所示。如果需要,我会发布完整的代码,任何熟悉phpmysql的人请通过它检查。希望你们理解这个问题。请通过它检查。

<?php 
    session_start(); 
    ?> 
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1256"> 

    <?php 
    header("Content-Type: text/html;charset=windows-1256"); 
    include_once('../includes/header_config.php'); 
    $sorting=' order by depe asc'; 
    if (isset($_POST['field'])) 
    { 
    if ($_POST['field'] != '') 
    { 
    $sorting=' order by '.$_POST['field']; 
    } 
    else 
    { 
    $sorting=' '; 
    } 
    } 
    ?> 

    <?php 
    //delete 
    if(isset($_POST['action']) && ($_POST['action']==3)) { 
    $sql="delete from hr_position where code=".$_POST['delid']; 
    $qry = DB_query($sql,$db); 
    $sql="delete from listsvalues where listid=40 and id=".$_POST['delid']; 
    $qry = DB_query($sql,$db); 
    $sql = "delete from hrnodes where contactid = '".$_POST['delid']."' and userid=15"; 
    $result2= DB_query($sql,$db); 
    } 
    ?> 


    <?php 
    //insert 

    if(isset($_POST['action']) && ($_POST['action']==2)) { 
    if ($_POST['invoicebreakdown']=='' || $_POST['invoicebreakdown']==0) $invoice_breakdown = 1; else $invoice_breakdown = $_POST['invoicebreakdown']; 
    for ($i = 1; $i <= $invoice_breakdown; $i++){ 
    if (isset($_POST['field1'.$i])) { 
    if(isset($_POST['cur_id_'.$i]) && $_POST['cur_id_'.$i]!='') $cur_id = $_POST['cur_id_'.$i]; else $cur_id =''; 
    if($cur_id=='') { 
      $sql="select max(code) as mx from hr_position"; 
      $qry = DB_query($sql,$db); 
      if ($res = DB_fetch_array($qry)) 
      { 
       if ($res['mx']==NULL) 
       { 

        $newid= 1; 
       } 
       else 
        { 
        $i =(int) $res['mx']; 
        $i=++$i; 
        $newid= $i; 
        } 
      }  

    echo $sql = "insert into hr_position (code,descr,lang) values (".$newid.",'".$_POST['field1'.$i]."',0)"; 
    $result= DB_query($sql,$db); 
    echo $sql = "insert into listsvalues (id,listid,userid,descr,lang,seq) values (".$newid.",40,-1,'".$_POST['field1'.$i]."',0,".$newid.")"; 
    $result= DB_query($sql,$db); 
    echo $sql = "insert into hr_position (code,descr,lang) values (".$newid.",'".$_POST['field2'.$i]."',1)"; 
    $result= DB_query($sql,$db); 
    echo $sql = "insert into listsvalues (id,listid,userid,descr,lang,seq) values (".$newid.",40,-1,'".$_POST['field2'.$i]."',2,".$newid.")"; 
    $result= DB_query($sql,$db); 
    echo $sql = "insert into hr_position (code,descr,lang) values (".$newid.",'".$_POST['field3'.$i]."',2)"; 
    $result= DB_query($sql,$db); 
    echo $sql = "insert into listsvalues (id,listid,userid,descr,lang,seq) values (".$newid.",40,-1,'".$_POST['field3'.$i]."',1,".$newid.")"; 
    $result= DB_query($sql,$db); 

    $sql = "select max(id) as mx from hrnodes "; 
    $result1= DB_query($sql,$db); 
    $newid1 = DB_fetch_array($result1); 
    $nwd = $newid1['mx']+1; 
    if ($_SESSION['lang']==0) {$name = $_POST['field1'.$i];} else if ($_SESSION['lang']==1) {$name = $_POST['field2'.$i];} else {$name = $_POST['field3'.$i];} 
    $sql = "insert into hrnodes (id,userid,title,position,parentid,contactid,acyear) VALUES 
    ('".$nwd."','15','".$name."','0','2','".$newid."','')"; 
    $result2= DB_query($sql,$db); 

    } 
    else 
    { 
    $sql = "update hr_position set descr='".$_POST['field1'.$i]."' where code =".$_POST['cur_id'.$i]." and lang = 0"; 
$result= DB_query($sql,$db); 
$sql = "update listsvalues set descr='".$_POST['field1'.$i]."' where listid=40 and id =".$_POST['cur_id'.$i]." and lang = 0"; 
$result= DB_query($sql,$db); 

$sql = "update hr_position set descr='".$_POST['field2'.$i]."' where code =".$_POST['cur_id'.$i]." and lang = 2"; 
$result= DB_query($sql,$db); 
$sql = "update listsvalues set descr='".$_POST['field2'.$i]."' where listid=40 and id =".$_POST['cur_id'.$i]." and lang = 2"; 
$result= DB_query($sql,$db); 
$sql = "update hr_position set descr='".$_POST['field3'.$i]."' where code =".$_POST['cur_id'.$i]." and lang = 1"; 
$result= DB_query($sql,$db); 
$sql = "update listsvalues set descr='".$_POST['field3'.$i]."' where listid=40 and id =".$_POST['cur_id'.$i]." and lang = 1"; 
$result= DB_query($sql,$db); 


if ($_SESSION['lang']==0) {$name = $_POST['field1'.$i];} else if ($_SESSION['lang']==1) {$name = $_POST['field2'.$i];} else {$name = $_POST['field3'.$i];} 

$sql = "update hrnodes set title='".$name."' where contactid = '".$_POST['cur_id'.$i]."' and userid=15"; 
$result2= DB_query($sql,$db); 
    } 
    } 
    } 
    } 
    ?> 

    <?php 
    if(!isset($_POST['breakdown'])) $_POST['breakdown']=0; 
    $sql = "SELECT distinct hr_position.code, hr_position.descr AS depe, hr_position_1.descr AS depf, hr_position_2.descr AS depa 
    FROM   hr_position INNER JOIN 
          hr_position hr_position_1 ON hr_position.code = hr_position_1.code INNER JOIN 
          hr_position hr_position_2 ON hr_position_1.code = hr_position_2.code 
    WHERE hr_position.code<>-1 and (hr_position.lang = 0) AND (hr_position_2.lang = 2) AND (hr_position_1.lang = 1)".$sorting; 

    $result= DB_query($sql,$db); 
    $num_rows = DB_num_rows($result); 
    $tot = $_POST['breakdown']+$num_rows; 
    ?> 


    <input type="hidden" name="amttype" value="" id="amttype"> 
    <input type="hidden" name="invoicebreakdown" value="<?php echo $tot;?>" id="invoicebreakdown"> 
    <input type="hidden" name="subbreakdown" value="" id="subbreakdown"> 



    <table width="95%" border="0" cellpadding="5" cellspacing="0" class="table_fullwidth"> 
    <tr><th width="30%">Position</th><th width="33%">Position</th> 
    <th width="32%">ÇÇáãÑßÒ</th> 
    </tr> 

    <?php $i=1; 
    while ($myrow1 = DB_fetch_array($result)) { 
    if ($i % 2==0) $bkg='td1'; else $bkg='td2'; 
    ?> 
    <tr id="trow_<?php echo $i;?>" class="<?php echo $bkg;?> "> 
    <td align="center"><input type="hidden" name="cur_id_<?php echo $i;?>" id="cur_id_<?php echo $i;?>" value="<?php echo $myrow1['code'];?>"> <input type="text" name="field1<?php echo $i;?>" id="field1<?php echo $i;?>" class="sel_long1 required" value="<?php echo $myrow1['depe'];?>" tabindex="<?php echo $i;?>_1" > </td> 

    <td align="center"><input tabindex="<?php echo $i;?>_2" class="sel_long1 required" type="text" name="field2<?php echo $i;?>" id="field2<?php echo $i;?>" value="<?php echo $myrow1['depf'] ;?>"> </td> 

    <td align="center"><input tabindex="<?php echo $i;?>_4" class="sel_long1" type="text" name="field3<?php echo $i;?>" id="field3_<?php echo $i;?>" value="<?php echo $myrow1['depa'] ;?>"> </td> 
    <td align="center"> <img src="<?php echo $site_path;?>images/del.png" width="20" class="cur" title="Delete" onclick="deleteitem('<?php echo $myrow1['code'];?>');"></td> 
    </tr> 
    <?php 
    $i++; 

    } 

    $breakdown = $_POST['breakdown']+$num_rows; 
    $j=$num_rows+1; 
    while($j<=$breakdown) { 
    if ($j % 2==0) $bkg='td1'; else $bkg='td2'; 
    ?> 




    <tr id="trow_<?php echo $j;?>" class="<?php echo $bkg;?> "><td align="center"><input type="hidden" name="cur_id_<?php echo $j;?>" id="cur_id_<?php echo $j;?>" value=""> 
    <input type="text" name="field1<?php echo $j;?>" id="field1<?php echo $j;?>" class="sel_long1 required" value="" tabindex="<?php echo $j;?>_1" > </td> 

    <td align="center" ><input class="sel_long1 required" type="text" name="field2<?php echo $j;?>" id="field2<?php echo $j;?>" value="" tabindex="<?php echo $j;?>_2"></td> 

    <td align="center"><input class="sel_long1 required" type="text" name="field3<?php echo $j;?>" id="field3<?php echo $j;?>" value="" tabindex="<?php echo $j;?>_4"> </td> 
    <td align="center"><img src="<?php echo $site_path;?>images/del.png" title="Delete" onclick="delete_row_details(<?php echo $j;?>)" width="20" class="cur"></td> 
    </tr> 
    <?php $j++; }?> 
    </table> 
    <div class="save_bt"><input name="save" id="savebt" class="no_marright submit-green save_right" value="Save" type="button" onclick="validate_save()" tabindex="<?php echo $j;?>"> </div> 

    <div id="did1"></div> 




    <script> 
    var $targets = $('#erp_from_sub').find('input, button , select'), 
     steps = $targets.map(function() { 
      return $(this).attr('tabindex'); 
     }).get(); 

    $('#erp_from_sub').on('keypress', 'input, button, select', function(e) { 
     if (e.keyCode == 13) { 
      var current = $.inArray($(this).attr('tabindex'), steps), 
       next = steps[++current % steps.length]; 
      $targets.filter('[tabindex="' + next + '"]').focus(); 
     } 
    }); 

    function deleteitem(a) { 
     if(confirm('Are you sure you want delete?')) { document.erp_from_sub.delid.value=a; document.getElementById('action').value='3';load_subpage('erp_from_sub');} 

     } 
     function delete_row_details(id) 
    { 
    var el = document.getElementById('trow_'+id); 
    if(confirm("Are you sure you want to delete this row")==true) 
    el.parentNode.removeChild(el); 
    /*calculateSum_credit();*/ 
    } 
    </script> 
+1

不使用大写字! ..这就像在网络中尖叫.. – scaisEdge

+0

清楚它插入或更新取决于$ cur_id的值。所以你需要调试发送给服务器的那个值。据推测,它总是空的,当它不应该。如果您无法弄清楚,请在此处发布HTML表单,然后尝试发送该值。顺便说一句,这段代码非常容易受到SQL注入攻击。您应该学会使用参数化查询和准备语句。 – ADyson

+0

好的..代码更新@ADyson –

回答

0

问题出在id和if if语句中。更正的代码是这样的。

<?php 
session_start(); 
?> 
<?php 
header("Content-Type: text/html;charset=windows-1256"); 
include_once('../includes/header_config.php'); 
$sorting=' order by depe asc'; 
if (isset($_POST['field'])) 
{ 
if ($_POST['field'] != '') 
{ 
$sorting=' order by '.$_POST['field']; 
} 
else 
{ 
$sorting=' '; 
} 
} 
?> 

<?php 
//delete 
if(isset($_POST['action']) && ($_POST['action']==3)) { 
$sql="delete from hr_position where code=".$_POST['delid']; 
$qry = DB_query($sql,$db); 
$sql="delete from listsvalues where listid=40 and id=".$_POST['delid']; 
$qry = DB_query($sql,$db); 
$sql = "delete from hrnodes where contactid = '".$_POST['delid']."' and userid=15"; 
$result2= DB_query($sql,$db); 
} 
?> 


<?php 
//insert 

if(isset($_POST['action']) && ($_POST['action']==2)) { 
if ($_POST['invoicebreakdown']=='' || $_POST['invoicebreakdown']==0) $invoice_breakdown = 1; else $invoice_breakdown = $_POST['invoicebreakdown']; 
for ($i = 1; $i <= $invoice_breakdown; $i++){ 

if(isset($_POST['cur_id_'.$i]) && $_POST['cur_id_'.$i]!='') $cur_id = $_POST['cur_id_'.$i]; else $cur_id =''; 
// Insert the value if the cur_id is null 
     if($cur_id=='') { 
     $sql="select max(code) as mx from hr_position"; 
     $qry = DB_query($sql,$db); 
     if ($res = DB_fetch_array($qry)) 
     { 
      if ($res[0] != NULL and $res[0] > 0){ 
      $newid = $res[0] + 1; 
      }else{ 
      $newid =1; 
     } 
     }  

$sql = "insert into hr_position (code,descr,lang) values (".$newid.",'".$_POST['field1'.$i]."',0)"; 
$result= DB_query($sql,$db); 

$sql = "insert into listsvalues (id,listid,userid,descr,lang,seq) values (".$newid.",40,-1,'".$_POST['field1'.$i]."',0,".$newid.")"; 
$result= DB_query($sql,$db); 

$sql = "insert into hr_position (code,descr,lang) values (".$newid.",'".$_POST['field2'.$i]."',2)"; 
$result= DB_query($sql,$db); 

$sql = "insert into listsvalues (id,listid,userid,descr,lang,seq) values (".$newid.",40,-1,'".$_POST['field2'.$i]."',2,".$newid.")"; 
$result= DB_query($sql,$db); 

$sql = "insert into hr_position (code,descr,lang) values (".$newid.",'".$_POST['field3'.$i]."',1)"; 
$result= DB_query($sql,$db); 

$sql = "insert into listsvalues (id,listid,userid,descr,lang,seq) values (".$newid.",40,-1,'".$_POST['field3'.$i]."',1,".$newid.")"; 
$result= DB_query($sql,$db); 

$sql = "select max(id) as mx from hrnodes "; 
$result1= DB_query($sql,$db); 
$newid1 = DB_fetch_array($result1); 
$nwd = $newid1['mx']+1; 
if ($_SESSION['lang']==0) {$name = $_POST['field1'.$i];} else if ($_SESSION['lang']==1) {$name = $_POST['field2'.$i];} else {$name = $_POST['field3'.$i];} 
$sql = "insert into hrnodes (id,userid,title,position,parentid,contactid,acyear) VALUES 
('".$nwd."','15','".$name."','0','2','".$newid."','')"; 
$result2= DB_query($sql,$db); 

} 
else 
{ 
$sql = "update hr_position set descr='".$_POST['field1'.$i]."' where code =".$_POST['cur_id_'.$i]." and lang = 0"; 
$result= DB_query($sql,$db); 
$sql = "update listsvalues set descr='".$_POST['field1'.$i]."' where listid=40 and id =".$_POST['cur_id_'.$i]." and lang = 0"; 
$result= DB_query($sql,$db); 

$sql = "update hr_position set descr='".$_POST['field2'.$i]."' where code =".$_POST['cur_id_'.$i]." and lang = 1"; 
$result= DB_query($sql,$db); 
$sql = "update listsvalues set descr='".$_POST['field2'.$i]."' where listid=40 and id =".$_POST['cur_id_'.$i]." and lang = 1"; 
$result= DB_query($sql,$db); 
$sql = "update hr_position set descr='".$_POST['field3'.$i]."' where code =".$_POST['cur_id_'.$i]." and lang = 2"; 
$result= DB_query($sql,$db); 
$sql = "update listsvalues set descr='".$_POST['field3'.$i]."' where listid=40 and id =".$_POST['cur_id_'.$i]." and lang = 2"; 
$result= DB_query($sql,$db); 


if ($_SESSION['lang']==0) {$name = $_POST['field1'.$i];} else if ($_SESSION['lang']==1) {$name = $_POST['field2'.$i];} else {$name = $_POST['field3'.$i];} 

$sql = "update hrnodes set title='".$name."' where contactid = '".$_POST['cur_id_'.$i]."' and userid=15"; 
$result2= DB_query($sql,$db); 
} 
} 
} 
?> 

<?php 
if(!isset($_POST['breakdown'])) $_POST['breakdown']=0; 
$sql = "SELECT distinct hr_position.code, hr_position.descr AS depe, hr_position_1.descr AS depf, hr_position_2.descr AS depa 
FROM   hr_position INNER JOIN 
         hr_position hr_position_1 ON hr_position.code = hr_position_1.code INNER JOIN 
         hr_position hr_position_2 ON hr_position_1.code = hr_position_2.code 
WHERE hr_position.code<>-1 and (hr_position.lang = 0) AND (hr_position_2.lang = 2) AND (hr_position_1.lang = 1)".$sorting; 

$result= DB_query($sql,$db); 
$num_rows = DB_num_rows($result); 
$tot = $_POST['breakdown']+$num_rows; 
?> 


<input type="hidden" name="amttype" value="" id="amttype"> 
<input type="hidden" name="invoicebreakdown" value="<?php echo $tot;?>" id="invoicebreakdown"> 
<input type="hidden" name="subbreakdown" value="" id="subbreakdown"> 



<table width="95%" border="0" cellpadding="5" cellspacing="0" class="table_fullwidth"> 
<tr><th width="30%">Position</th><th width="33%">Position</th> 
<th width="32%">ÇÇáãÑßÒ</th> 
</tr> 

<?php $i=1; 
while ($myrow1 = DB_fetch_array($result)) { 
if ($i % 2==0) $bkg='td1'; else $bkg='td2'; 
?> 

<tr id="trow_<?php echo $i;?>" class="<?php echo $bkg;?> "> 
<td align="center"><input type="hidden" name="cur_id_<?php echo $i;?>" id="cur_id_<?php echo $i;?>" value="<?php echo $myrow1['code'];?>"> <input type="text" name="field1<?php echo $i;?>" id="field1<?php echo $i;?>" class="sel_long1 required" value="<?php echo $myrow1['depe'];?>" tabindex="<?php echo $i;?>_1" > </td> 

<td align="center"><input tabindex="<?php echo $i;?>_2" class="sel_long1 required" type="text" name="field2<?php echo $i;?>" id="field2<?php echo $i;?>" value="<?php echo $myrow1['depf'] ;?>"> </td> 

<td align="center"><input tabindex="<?php echo $i;?>_4" class="sel_long1" type="text" name="field3<?php echo $i;?>" id="field3_<?php echo $i;?>" value="<?php echo $myrow1['depa'] ;?>"> </td> 
<td align="center"> <img src="<?php echo $site_path;?>images/del.png" width="20" class="cur" title="Delete" onclick="deleteitem('<?php echo $myrow1['code'];?>');"></td> 
</tr> 
<?php 
$i++; 

} 



$breakdown = $_POST['breakdown']+$num_rows; 
$j=$num_rows+1; 
while($j<=$breakdown) { 
if ($j % 2==0) $bkg='td1'; else $bkg='td2'; 
?> 




<tr id="trow_<?php echo $j;?>" class="<?php echo $bkg;?> "><td align="center"> 
<input type="hidden" name="cur_id_<?php echo $j;?>" id="cur_id_<?php echo $j;?>" value=""> 
<input type="text" name="field1<?php echo $j;?>" id="field1<?php echo $j;?>" class="sel_long1 required" value="" tabindex="<?php echo $j;?>_1" > </td> 

<td align="center" ><input class="sel_long1 required" type="text" name="field2<?php echo $j;?>" id="field2<?php echo $j;?>" value="" tabindex="<?php echo $j;?>_2"></td> 

<td align="center"><input class="sel_long1 required" type="text" name="field3<?php echo $j;?>" id="field3<?php echo $j;?>" value="" tabindex="<?php echo $j;?>_4"> </td> 
<td align="center"><img src="<?php echo $site_path;?>images/del.png" title="Delete" onclick="delete_row_details(<?php echo $j;?>)" width="20" class="cur"></td> 
</tr> 
<?php $j++; }?> 
</table> 
<div class="save_bt"><input name="save" id="savebt" class="no_marright submit-green save_right" value="Save" type="button" onclick="validate_save()" tabindex="<?php echo $j;?>"> </div> 

<div id="did1"></div> 




<script> 
var $targets = $('#erp_from_sub').find('input, button , select'), 
    steps = $targets.map(function() { 
     return $(this).attr('tabindex'); 
    }).get(); 

$('#erp_from_sub').on('keypress', 'input, button, select', function(e) { 
    if (e.keyCode == 13) { 
     var current = $.inArray($(this).attr('tabindex'), steps), 
      next = steps[++current % steps.length]; 
     $targets.filter('[tabindex="' + next + '"]').focus(); 
    } 
}); 

function deleteitem(a) { 
    if(confirm('Are you sure you want delete?')) { document.erp_from_sub.delid.value=a; document.getElementById('action').value='3';load_subpage('erp_from_sub');} 

    } 
    function delete_row_details(id) 
{ 
var el = document.getElementById('trow_'+id); 
if(confirm("Are you sure you want to delete this row")==true) 
el.parentNode.removeChild(el); 
/*calculateSum_credit();*/ 
} 
</script>