EasyUI Forum
May 03, 2024, 04:52:10 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: CRUD application delete not working [resolved]  (Read 10067 times)
andyj
Jr. Member
**
Posts: 57



View Profile
« on: July 12, 2013, 12:55:34 AM »

I have built a datagrid with pop up form editing based on the CRUD application demo
http://www.jeasyui.com/tutorial/app/crud.php

Everything works fine, except the delete record function.
It fires, the prompt comes up, no error message but I don't think it's getting the record ID for some reason.
Can anyone see anything incorrect in my code? Thanks

Javascript delete function:
Code:
		function deleteRecord(){
var row = $('#dg').datagrid('getSelected');
if (row){
$.messager.confirm('Confirm','Are you sure you want to delete this record?',function(r){
if (r){
$.post('data_delete.php',{id:row.id},function(result){
if (result.success){
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({ // show error message
title: 'Error',
msg: result.msg
});
}
},'json');
}
});
}
}

Datagrid html:
Code:
				<table id="dg" title="Classes" class="easyui-datagrid" 
url="data_select.php" idField="class_id" striped="true" loadMsg="Hey patience is a virtue"
toolbar="#toolbar" pagination="true" pageSize="30"
rownumbers="true" fitColumns="true" showFooter="true" singleSelect="true"
data-options="onDblClickRow:function(rowIndex, rowData){
editRecord();}">
<thead>
<tr>
<th id="idclass_id" field="class_id" width="35" align="right">ID</th>
<th id="idTimeCreated" field="TimeCreated" width="80">Created</th>
<th id="idTimeModified" field="TimeModified" width="80">Last Modified</th>
<th id="idClass" field="Class" >Class</th>
<th id="dgIsActive" field="IsActive" width="80">Active?</th>
<th id="idsortorder" field="sortorder" width="80">Sort Order</th>
</tr>
</thead>
</table>
<div id="toolbar">
<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="insertRecord()">New Line Item</a> |
<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editRecord()">Edit Line Item</a> |
<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteRecord()">Remove Line Item</a>
</div>

data_delete.php file:
Code:
<?php
$id 
intval($_REQUEST['class_id']);
include 
'../../common/conn.php';
$sql "DELETE FROM class where class_id=$id";
$result = @mysql_query($sql);
if (
$result){
echo json_encode(array('success'=>true));
} else {
echo json_encode(array('msg'=>'An error occurred while attempting to delete the record.'));
}
?>

Thanks for any insights...  Huh
« Last Edit: July 12, 2013, 01:41:47 AM by andyj » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 12, 2013, 01:35:25 AM »

Please replace your code
Code:
$.post('data_delete.php',{id:row.id},function(result){
//...
});
with
Code:
$.post('data_delete.php',{class_id:row.class_id},function(result){
//...
});
Logged
andyj
Jr. Member
**
Posts: 57



View Profile
« Reply #2 on: July 12, 2013, 01:37:39 AM »

You're a legend. Thanks very much. Works like magic  Grin
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!