EasyUI Forum
May 17, 2024, 12:35:51 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [Help!] Editing in DataGrid after change cell, can't updateurl (php)  (Read 9992 times)
kg
Newbie
*
Posts: 9


View Profile
« 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
Code:
	<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
Code:
<?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

Code:
<?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();


?>
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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.
Code:
$dr_staffcode = $_REQUEST['dr_staffcode'];
//...
$sql = "update ... 'where dr_staffcode='$dr_staffcode'";
Logged
kg
Newbie
*
Posts: 9


View Profile
« Reply #2 on: January 20, 2014, 09:05:30 PM »

stworthy,

thank you for your reply.
Logged
hohanoah
Newbie
*
Posts: 1


View Profile
« Reply #3 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 :
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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!