繁体   English   中英

从 Javascript 中的编辑表单传递 id

[英]Pass id from the edit form in Javascript

我正在尝试使用 JavaScript 从表单和表中传递数据以编辑表单。 问题是当我尝试编辑它时它不会更新表单和表格。 有人至少可以通过给我一个代码应该是什么的例子来帮助我吗?

function SYS_add_product_form(){
           var pullout_id=$('#tbl_pending_pullout_id').val();
           $('#dialog1').remove();
           $('body').append("<div id='dialog1'></div>"); /*Creates a virtual DOM <div id='dialog1'></div>*/
           SYS_dialog3('#dialog1','495','950px','Create Pullout Request',function(){  });
         $.post(URL+"index.php/pullout_request/loadPullOutRequestForm",{pullout_id:''}).done(function(data){
            $("#dialog1").html(data).dialog("open");
        });  
     }

function pullout_edit(x){
        var pullout_id=$('#tbl_pending_pullout_id'+x).val();
SYS_dialog3('#dialog1','495','950px','Edit Pullout Request',function(){  });
$.post(URL+"index.php/pullout_request/loadPullOutRequestForm",{pullout_id:'edit'}).done(function(data){
    $("#dialog1").html(data).dialog("open");
}); 

添加时没有问题。 但是,我认为问题可能出在我的 elseif 语句上。

$pullout_id=$_POST['pullout_id'];
if ($pullout_id=='') {

$pullout_id=$this->mainmodel->getMaxId("across_pullout","pullout_id")+1;
$this->db->query("insert into across_pullout values('$pullout_id','$pullout_num','$date_requested','$user_accountid','','','','','','','0','$description','$counter','$year','1');");
for($x=0;$x<count($pid);$x++){
    $pid1=$pid[$x];
    $qty1=$qty[$x];
    if($qty1==0){ $msg="All Quantities should be greater than zero"; }
    $this->db->query("insert into across_pullout_items values('','$pullout_id','$pid1','$qty1','1');");
}
}else if($pullout_id=='edit') {
$sql .= "UPDATE `across_pullout` SET date_requested='$date_requested', `description`='$description' where pullout_num='$pullout_num' and  remark='1';";
 $sql .= "UPDATE across_pullout_items set pullout_qty='$pullout_qty' where remark='1';";
}

首先,你使用 $this->db->query 的方式可能会导致查询注入。 所以我建议你使用如下。

$sql = "UPDATE `across_pullout` SET date_requested=?, `description`=? where pullout_num=? and  remark='1'"
$this->db->query($sql, array($date_requested, $description, $pullout_num));

而 $this->db->query() 不接受多个查询。 所以你需要调用 $this->db->query() 两次来执行 2 个查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM