在Javascript中从编辑表单传递id
我正在尝试使用JavaScript将表单和表中的数据传递给编辑表单。问题是当我试图编辑表单和表时,它不会更新表单和表。至少有人能帮我举个代码应该是什么的例子吗在Javascript中从编辑表单传递id,javascript,php,mysql,ajax,codeigniter,Javascript,Php,Mysql,Ajax,Codeigniter,我正在尝试使用JavaScript将表单和表中的数据传递给编辑表单。问题是当我试图编辑表单和表时,它不会更新表单和表。至少有人能帮我举个代码应该是什么的例子吗 function SYS_add_product_form(){ var pullout_id=$('#tbl_pending_pullout_id').val(); $('#dialog1').remove(); $('body').append("<div id=
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两次来执行两个查询