Title: [Help!] Editing in DataGrid after change cell, can't updateurl (php)
Post by: kg on January 20, 2014, 07:57:19 PM
Hi All, I use edatagrid to updateUrl: (php file & update mysql), but not working. Please help & tell me, what's wrong in staffupdatedata.php / staffrecord.html both file. url: 'staffgetdata.php', <-- Sucess saveUrl: 'staffsavedata.php', <-- Sucess updateUrl: 'staffupdatedata.php', <-- not working & no change in database destroyUrl: 'staffdestroydata.php' <-- Sucess staffrecord.html <title>Staff Record</title> <link rel="stylesheet" type="text/css" href="themes/default/easyui.css"> <link rel="stylesheet" type="text/css" href="themes/icon.css"> <script type="text/javascript" src="plugins/jquery-1.7.2.js"></script> <script type="text/javascript" src="plugins/jquery.easyui.min.js"></script> <script type="text/javascript" src="plugins/jquery.edatagrid.js"></script> <script type="text/javascript"> $(function(){ $('#frm_staffrec').edatagrid({ autoSave: true, url: 'staffgetdata.php', saveUrl: 'staffsavedata.php', updateUrl: 'staffupdatedata.php', destroyUrl: 'staffdestroydata.php' }); }); </script> </head> <body> <h1>Staff Record</h1>
<div id="toolbar"> <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#frm_staffrec').edatagrid('addRow')">New</a> <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:$('#frm_staffrec').edatagrid('destroyRow')">Destroy</a> <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$('#frm_staffrec').edatagrid('saveRow')">Save</a> <a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#frm_staffrec').edatagrid('cancelRow')">Cancel</a> </div> <table id="frm_staffrec" style="width:600px;height:600px" idField="dr_staffcode" url="staffgetdata.php" toolbar="#toolbar" pagination="true" rownumbers="true" fitColumns="true" title="Staff Data (double click to edit)" singleSelect="true">
<thead> <tr> <th field="dr_staffcode" width="100" editor="{type:'validatebox',options:{required:true}}">Staff Code</th> <th field="dr_staffname" width="100" editor="{type:'validatebox',options:{required:true}}">Staff Name</th> <th field="dr_stafflevel" width="80" editor="numberbox">Staff Level</th> <th field="dr_staffemail" width="150" editor="{type:'validatebox',options:{required:true,validType:'email'}}">Email</th> <th field="dr_staffactive" width="50" editor="numberbox">Active</th> <!-- <th field="dr_staffcard" width="100" align="right" editor="{type:'numberbox',options:{precision:1}}">List Price</th> <th field="unitcost" width="100" align="right" editor="numberbox">Unit Cost</th> !-->
</tr> </thead> </table> </body> </html> staffupdatedata.php <?php
$id = $_REQUEST['id']; $dr_staffcode = $_REQUEST['dr_staffcode']; $dr_staffname = $_REQUEST['dr_staffname']; $dr_stafflevel = $_REQUEST['dr_stafflevel']; $dr_staffemail = $_REQUEST['dr_staffemail']; $dr_staffactive = $_REQUEST['dr_staffactive']; $dr_staffcarda = trim($_REQUEST['dr_staffcode']," "); $dr_staffcard = $dr_staffcarda."0%T";
include 'mysqlconfig.php';
$sql = "update dr_staff set dr_staffcode=$dr_staffcode, dr_staffname=$dr_staffname, dr_stafflevel=$dr_stafflevel, dr_staffemail=$dr_staffemail, dr_staffactive=$dr_staffactive, dr_staffcard=$dr_staffcard where dr_staffcode='$id'"; @$db->query($sql); echo json_encode(array( 'dr_staffcode' => $id, 'dr_staffname' => $dr_staffname, 'dr_stafflevel' => $dr_stafflevel, 'dr_staffemail' => $dr_staffemail, 'dr_staffactive' => $dr_staffactive ));
?>
staffgetdata.php <?php include 'mysqlconfig.php';
$myArray = array(); if ($result = $db->query("SELECT * FROM dr_staff")) { $tempArray = array(); while($row = $result->fetch_object()) { $tempArray = $row; array_push($myArray, $tempArray); } echo json_encode($myArray); } $result->close(); $db->close(); ?>
Title: Re: [Help!] Editing in DataGrid after change cell, can't updateurl (php)
Post by: stworthy on January 20, 2014, 08:10:43 PM
Notice that your id field name is 'dr_staffcode' not 'id', so the 'dr_staffcode' parameter will be posted to server. In your server code, you need to get the correct 'dr_staffcode' parameter value and pass it to the sql statement. $dr_staffcode = $_REQUEST['dr_staffcode']; //... $sql = "update ... 'where dr_staffcode='$dr_staffcode'";
Title: Re: [Help!] Editing in DataGrid after change cell, can't updateurl (php)
Post by: kg on January 20, 2014, 09:05:30 PM
stworthy,
thank you for your reply.
Title: Re: [Help!] Editing in DataGrid after change cell, can't updateurl (php)
Post by: hohanoah on September 14, 2016, 09:42:53 AM
I Have similar problem, but not success in destroy_user.php (is not working) here is my code : <?php
$id = intval($_REQUEST['id']);
include 'conn.php';
$sql = "delete from users where id=$id"; @$conn->query($sql); echo json_encode(array("success"=>true)); ?> update, save, and add rows succeed. but delete row fail. please help
|