php - jQ Grid problems with edit form does not send request to the SQL database -


i new user of jq grid , implement edit form. grid linked sql database. data of sql database correctly displayed in grid.

when select row , click on edit button, edit form appearing data of selected row. when i'm modifying information , click submit, modification displayed on grid ** sql database not updated**. if refresh page, grid display information of sql database , can see modifications have not been made in database (the data displayed same displayed ).

can me out ?

here grid code :

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>my first grid</title>  <link rel="stylesheet" type="text/css" media="screen" href="jquery-ui-1.10.2/themes/base/jquery.ui.all.css" /> <link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" /> <link rel="stylesheet" type="text/css" media="screen" href="ui.jqgrid.css" />  <style type="text/css"> html, body {     margin: 0;     padding: 0;     font-size: 75%; } </style>  <script src="js/jquery-1.9.0.min.js" type="text/javascript"></script> <script src="js/i18n/grid.locale-en.js" type="text/javascript"></script> <script src="js/jquery.jqgrid.min.js" type="text/javascript"></script> <script src="js/jquery.jqgrid.src.js" type="text/javascript"></script>  <script type="text/javascript"> jquery.extend(jquery.jgrid.defaults, { autoencode:true }); </script>   <script type="text/javascript">  $(function(){    $("#editgrid").jqgrid({     url:'example.php',     datatype: 'xml',     mtype: 'get',     colnames:['numero','nature', 'nom','qualification','prixmax','prixmin'],     colmodel :[        {name:'numero', index:'numero', width:55,celledit:true, celledittype:'text'},        {name:'nature',       index:'nature',       editable: true,       edittype: 'text',       editoptions: { size: 10},       editrules: {required: true },       formoptions: { label: 'nature' },       width:90},        {name:'nom', index:'nom', width:180, align:'right',editable: true,edittype:'textarea'},        {name:'qualification', index:'qualification', width:80, align:'right',editable: true,edittype:'textarea'},        {name:'prixmax', index:'prixmax', width:80, align:'right',editable: true,edittype:'textarea'},        {name:'prixmin', index:'prixmin', width:150, sortable:false,editable: true,edittype:'textarea'}      ],     pager: '#pager',     rownum:10,     rowlist:[10,20,30],     sortname: 'numero',     sortorder: 'desc',     viewrecords: true,     emptyrecords: "nothing display",     gridview: true,     editurl:'edit.php',     edittype:'text',     caption: 'my first grid',     loadonce:true, });     $("#bedata").click(function(){     var gr = jquery("#editgrid").jqgrid('getgridparam','selrow');     if( gr != null ) jquery("#editgrid").jqgrid('editgridrow',gr,{height:280,reloadaftersubmit:false,edit:true},{editurl:'edit.php',mtype:'post'});     else alert("please select row"); }); });  </script>  </head> <body>  <table id="editgrid"><tr><td/></tr></table>  <div id="pager"></div>  <input type="button" id="bedata" value="edit selected" /> </body> </html> 

and here edit.php supposed update database :

<?php  $dbhost ="localhost"; $dbuser="root"; $dbpassword=""; $database="geoclients"; $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("connection error: " . mysql_error());  mysql_select_db($database) or die("error connecting db.");  $tablename="clients"; mysql_set_charset('utf8',$database); mysql_query("set names 'utf8'");       $num     =  mysql_real_escape_string($_post['numero']);     $nat   =  mysql_real_escape_string($_post['nature']);     $nom =  mysql_real_escape_string($_post['nom']);     $qual    =  mysql_real_escape_string($_post['qualification']);     $prixmax  =  mysql_real_escape_string($_post['prixmax']);     $prixmin   =  mysql_real_escape_string($_post['prixmin']);      $sql = "update ".$tablename." set nature = '".$nat."', nom = '".$nom."', qualification = '".$qual."', prixmax = '".$prixmax."' , prixmin = '".$prixmin."' numero = ".$num.";";      echo $sql;   $result=mysql_query($sql) or die(mysql_error());  mysql_close($db);    ?> 

the connexion database same code used fill grid in first place (which working), i'm assuming connexion code working. have checked sql syntax of request seems ok. sql database hosted on local wamp server.

thank in advance.

i use jqgrid, can't ever used in-built editing, prefer handling stuff myself have better control on it.

see if works you:

$("#bedata").click(function() {      var grid = $("#editgrid"),         row  = grid.getgridparam('selrow'),         data = grid.getrowdata(row);      if (row != null) {         // send ajax request first         $.ajax({             url: edit.php,             data: data,             type: 'post',             success: function(data) {                 console.log(data); // check returned string here                // here can put code handle rows updating             }         });     }     else alert('please select row'); }); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -