【问题标题】:Pass id from the edit form in Javascript从 Javascript 的编辑表单中传递 id
【发布时间】:2020-04-28 15:48:41
【问题描述】:

我正在尝试使用 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';";
}

【问题讨论】:

    标签: javascript php mysql ajax codeigniter


    【解决方案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 个查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-15
      • 1970-01-01
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多