<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: How to insert data to mysql database from add dialog in jqgrid</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/how-to-insert-data-to-mysql-database-from-add-dialog-in-jqgrid</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/how-to-insert-data-to-mysql-database-from-add-dialog-in-jqgrid/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>hemang.gandhi on How to insert data to mysql database from add dialog in jqgrid</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-to-insert-data-to-mysql-database-from-add-dialog-in-jqgrid#p27807</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-to-insert-data-to-mysql-database-from-add-dialog-in-jqgrid#p27807</guid>
        	        	<description><![CDATA[<p>I am trying to have a jqgrid on my webpage with all the functionality.</p>
<p>Currently I am able to fill the grid with data from mysql database.</p>
<p>Now I  have kept add:true in the navgrid option and with the &#39;+&#39; icon it opens</p>
<p>a add dialog box with 3 fields which on submit I need to add to mysql  database.</p>
<p>Here&#39;s my jqgrid code:</p>
</p>
<pre class="lang-sql prettyprint prettyprinted"><p><input type='button' class='sfcodeselect' name='sfselectit4508' value='Select Code' data-codeid='sfcode4508' /></p><div class='sfcode' id='sfcode4508'>&#60;script type=&#34;text/javascript&#34;&#62;
jQuery(document).ready(function(){
$(&#34;#grid&#34;).jqGrid({ 
   // data: mydata, 
    datatype: &#39;json&#39;,
    mtype: &#39;POST&#39;,
    url: &#39;showResources.php&#39;,
    width: 700, 
    colNames:[&#34;LAB NAME&#34;,&#34;RESOURCE NAME&#34;,&#34;DESCRIPTION&#34;], 
    colModel:[
    {name:&#39;lab_name&#39;, index:&#39;lab_name&#39;, width:40,editable:true, edittype: &#39;select&#39;, <br />editoptions:{value:&#34;nccs:NCCS;tcs:TCS;iisc:IISC;icgeb:ICGEB&#34;, <br />dataInit:function(elem) 
        {
                $(elem).width(&#39;auto&#39;);
        }
}},
    {name:&#39;resource_name&#39;, index:&#39;resource_name&#39;, width:50,editable:true, <br />editoptions:{size:&#39;auto&#39;}},
    {name:&#39;description&#39;, index:&#39;description&#39;, width:100,editable:true, <br />edittype: &#39;textarea&#39;, editoptions:{rows:&#34;2&#34;,cols:&#34;20&#34;}},
    ], 
    pager: &#34;#pager&#34;, 
    rowNum:10, 
    rownumbers: true,
    rowList:[10,20,30],
    gridview: true,
    sortname: &#39;id&#39;, 
    viewrecords: true,
    loadonce: true,
    sortorder: &#34;desc&#34;, 
    caption:&#34;Resources&#34;,
    height: 250,
    editurl: &#39;addResource.php&#39;      
    }).navGrid(&#39;#pager&#39;,{edit:false,add:true,del:false,search:true},{width: &#39;330&#39;, <br />closeAfterAdd: true });  
});
&#60;/script&#62;<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: &#39;addResource.php&#39; is where my </p><p> logic for adding the row is which is:</p>
<p>code:</p><br /></pre>
<pre class="lang-sql prettyprint prettyprinted"><p><input type='button' class='sfcodeselect' name='sfselectit3336' value='Select Code' data-codeid='sfcode3336' /></p><div class='sfcode' id='sfcode3336'>$lab_name = $_POST[&#39;lab_name&#39;];  //lab_name field from POST above
    $resource_name = $_POST[&#39;resource_name&#39;]; //resource_name field from POST above
    $description = $_POST[&#39;description&#39;];  //description field from POST above
    $tb_name = &#39;tb_systb_resources&#39;;

    $add_query = &#34;INSERT INTO $tb_name (&#39;&#39;,&#39;lab_name&#39;,&#39;resource_name&#39;,&#39;description&#39;) <br />VALUES (&#39;&#39;,$lab_name,$resource_name,$description)&#34;;
    $result = mysql_query($add_query);
    if($result)
    {
        echo(&#34;&#60;br&#62;Input data is succeed&#34;);
    } 
    else
    {
        echo(&#34;&#60;br&#62;Input data is fail&#34;);
    }<br /><br /><br /></div><p>Now when the page is loaded it says</p>
<p>Notice: Undefined index: lab_name in /opt/lampp/htdocs/hemang/addResource.php on line 10</p>
<p>Notice: Undefined index: resource_name in /opt/lampp/htdocs/hemang/addResource.php on line 11</p>
<p>Notice: Undefined index: description in /opt/lampp/htdocs/hemang/addResource.php on line 12</p>
<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&#39; values  from the submit button in add dialog box.</p>
<p>Please help.</p></pre>
]]></description>
        	        	<pubDate>Thu, 29 Nov 2012 09:03:25 +0200</pubDate>
        </item>
</channel>
</rss>