簡體   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