简体   繁体   中英

Pass id from the edit form in Javascript

I am trying to pass data from a form and table to edit a form, using JavaScript. The problem is that it doesn't update the form and table when I try to edit it. Can someone at least help me by giving me an example of what the code should be?

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");
}); 

When adding there is no problem. But, I think maybe the problem is my elseif statement.

$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';";
}

First of all, the way you use $this->db->query may cause query injection. So I suggest you to use as follows.

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

And $this->db->query() does not accept multiple queries. So you need to call $this->db->query() twice to execute 2 queries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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