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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<div class="sfcode"><script type="text/javascript"><br /> jQuery(document).ready(function(){<br /> $("#grid").jqGrid({<br /> // data: mydata,<br /> datatype: 'json',<br /> mtype: 'POST',<br /> url: 'showResources.php',<br /> width: 700,<br /> colNames:["LAB NAME","RESOURCE NAME","DESCRIPTION"],<br /> colModel:[<br /> {name:'lab_name', index:'lab_name', width:40,editable:true, edittype: 'select', <br />editoptions:{value:"nccs:NCCS;tcs:TCS;iisc:IISC;icgeb:ICGEB", <br />dataInit:function(elem)<br /> {<br /> $(elem).width('auto');<br /> }<br /> }},<br /> {name:'resource_name', index:'resource_name', width:50,editable:true, <br />editoptions:{size:'auto'}},<br /> {name:'description', index:'description', width:100,editable:true, <br />edittype: 'textarea', editoptions:{rows:"2",cols:"20"}},<br /> ],<br /> pager: "#pager",<br /> rowNum:10,<br /> rownumbers: true,<br /> rowList:[10,20,30],<br /> gridview: true,<br /> sortname: 'id',<br /> viewrecords: true,<br /> loadonce: true,<br /> sortorder: "desc",<br /> caption:"Resources",<br /> height: 250,<br /> editurl: 'addResource.php'<br /> }).navGrid('#pager',{edit:false,add:true,del:false,search:true},{width: '330', <br />closeAfterAdd: true });<br /> });<br /> </script><br /><br /></div><p>Here url:showResource.php is the page where I have the logic to fetch </p><p>data into grid from mysql, and editurl: 'addResource.php' is where my </p><p> logic for adding the row is which is:</p><br /> <p>code:</p><br /> |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<div class="sfcode">$lab_name = $_POST['lab_name']; //lab_name field from POST above<br /> $resource_name = $_POST['resource_name']; //resource_name field from POST above<br /> $description = $_POST['description']; //description field from POST above<br /> $tb_name = 'tb_systb_resources';<br /> <br /> $add_query = "INSERT INTO $tb_name ('','lab_name','resource_name','description') <br />VALUES ('',$lab_name,$resource_name,$description)";<br /> $result = mysql_query($add_query);<br /> if($result)<br /> {<br /> echo("<br />Input data is succeed");<br /> }<br /> else<br /> {<br /> echo("<br />Input data is fail");<br /> }<br /><br /><br /></div><p>Now when the page is loaded it says</p><br /> <p>Notice: Undefined index: lab_name in /opt/lampp/htdocs/hemang/addResource.php on line 10</p><br /> <p>Notice: Undefined index: resource_name in /opt/lampp/htdocs/hemang/addResource.php on line 11</p><br /> <p>Notice: Undefined index: description in /opt/lampp/htdocs/hemang/addResource.php on line 12</p><br /> <p>which i have printed and the grid is filled, and the data does add from the </p><p>dialog but does not store to db. So when I refresh the page or grid it disappears. </p><p>I am not sure of how to pass the 3 fields' values from the submit button in add dialog box.</p><br /> <p>Please help.</p> |
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top