对话框mysql插入数据,如何从jqgrid中的添加对话框向mysql数据库添加数据

作者在博客中描述了如何在使用jQuery Grid时,尝试通过add选项添加新数据到MySQL数据库,但遇到未定义索引错误。文章详细介绍了问题所在并寻求帮助,希望解决如何正确从添加对话框传递字段值到后台服务器的问题。
摘要由CSDN通过智能技术生成

I am trying to have a jqgrid on my webpage with all the functionality. Currently I am able to fill the grid with data from mysql database. Now I have kept add:true in the navgrid option and with the '+' icon it opens a add dialog box with 3 fields which on submit I need to add to mysql database. Here's my jqgrid code:

jQuery(document).ready(function(){

$("#grid").jqGrid({

// data: mydata,

datatype: 'json',

mtype: 'POST',

url: 'showResources.php',

width: 700,

colNames:["LAB NAME","RESOURCE NAME","DESCRIPTION"],

colModel:[

{name:'lab_name', index:'lab_name', width:40,editable:true, edittype: 'select', editoptions:{value:"nccs:NCCS;tcs:TCS;iisc:IISC;icgeb:ICGEB", dataInit: function(elem)

{

$(elem).width('auto');

}

}},

{name:'resource_name', index:'resource_name', width:50,editable:true, editoptions:{size:'auto'}},

{name:'description', index:'description', width:100,editable:true, edittype: 'textarea', editoptions:{rows:"2",cols:"20"}},

],

pager: "#pager",

rowNum:10,

rownumbers: true,

rowList:[10,20,30],

gridview: true,

sortname: 'id',

viewrecords: true,

loadonce: true,

sortorder: "desc",

caption:"Resources",

height: 250,

editurl: 'addResource.php'

}).navGrid('#pager',{edit:false,add:true,del:false,search:true},{width: '330', closeAfterAdd: true });

});

</script>

Here url:showResource.php is the page where I have the logic to fetch data into grid from mysql, and editurl: 'addResource.php' is where my logic for adding the row is which is:

code:

$lab_name = $_POST['lab_name']; //lab_name field from POST above

$resource_name = $_POST['resource_name']; //resource_name field from POST above

$description = $_POST['description']; //description field from POST above

$tb_name = 'tb_systb_resources';

$add_query = "INSERT INTO $tb_name ('','lab_name','resource_name','description') VALUES ('',$lab_name,$resource_name,$description)";

$result = mysql_query($add_query);

if($result)

{

echo("
Input data is succeed");

}

else

{

echo("
Input data is fail");

}

Now when the page is loaded it says

Notice: Undefined index: lab_name in /opt/lampp/htdocs/hemang/addResource.php on line 10

Notice: Undefined index: resource_name in /opt/lampp/htdocs/hemang/addResource.php on line 11

Notice: Undefined index: description in /opt/lampp/htdocs/hemang/addResource.php on line 12

which i have printed and the grid is filled, and the data does add from the dialog but does not store to db. So when I refresh the page or grid it disappears. I am not sure of how to pass the 3 fields' values from the submit button in add dialog box.

Please help.

解决方案("#grid").jqGrid({

// data: mydata,

datatype: 'json',

mtype: 'POST',

url: 'showResources.php',

width: 700,

colNames:["LAB NAME","RESOURCE NAME","DESCRIPTION"],

colModel:[

{name:'lab_name', index:'lab_name', width:40,editable:true, edittype: 'select', editoptions:{value:"nccs:NCCS;tcs:TCS;iisc:IISC;icgeb:ICGEB", dataInit: function(elem)

{

(elem).width('auto');

}

}},

{name:'resource_name', index:'resource_name', width:50,editable:true, editoptions:{size:'auto'}},

{name:'description', index:'description', width:100,editable:true, edittype: 'textarea', editoptions:{rows:"2",cols:"20"}},

],

pager: "#pager",

rowNum:10,

rownumbers: true,

rowList:[10,20,30],

gridview: true,

sortname: 'id',

viewrecords: true,

loadonce: true,

sortorder: "desc",

caption:"Resources",

height: 250,

editurl: 'addResource.php'

}).navGrid('#pager',{edit:false,add:true,del:false,search:true},{width: '330', closeAfterAdd: true });

});

</script>

Here url:showResource.php is the page where I have the logic to fetch data into grid from mysql, and editurl: 'addResource.php' is where my logic for adding the row is which is:

code:

lab_name =

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值