3

I'm using jeasy-ui to populate a data grid. I had this working earlier today, then decided to move some files around which didn't work and eventually rolled back my changes.

Unfortunately now it only populates the tables and allows me to delete rows however saving and inserting seems to do nothing. The worst part is I know it's something simple but I've been at it for 4 hours now and it's time to ask what I'm not seeing.

EDIT

Was missing a comma after 'date' => $date on save_user.php. Knew it was something simple. Thanks for the help.

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="keywords" content="jquery,ui,easy,easyui,web">
    <meta name="description" content="">

    <title>Scheduler</title>
    <link rel="stylesheet" type="text/css" href="css/black/easyui.css">
    <link rel="stylesheet" type="text/css" href="css/icon.css">

    <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="js/jquery-ui.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="js/jquery.datagrid.js"></script>
    <script type="text/javascript">

        //create datafields

        $(function(){
            $('#dg').edatagrid({
                url: 'get_users.php',
                saveUrl: 'save_user.php',
                updateUrl: 'update_user.php',
                destroyUrl: 'destroy_user.php'      
            });
        });

    </script>
</head>
<body>

    <table id="dg" title="Edit Teams" style="width:700px;height:250px"
            toolbar="#toolbar" pagination="true" idField="id"
            rownumbers="true" fitColumns="true" singleSelect="true">
        <thead>


            <tr>
                <th field="date" width="50" editor="{type:'validatebox',options:{required:true}}">Date</th>
                <th field="starttime" width="50" editor="{type:'validatebox',options:{required:true}}">Time Start</th>
                <th field="endtime" width="50" editor="{type:'validatebox',options:{required:true}}">Time Finish</th>
                <th field="team1" width="50" editor="{type:'validatebox',options:{required:true}}">Team 1</th>
                <th field="team2" width="50" editor="{type:'validatebox',options:{required:true}}">Team 2</th>
            </tr>
        </thead>
    </table>

    <div id="toolbar">
        <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#dg').edatagrid('addRow')">New</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:$('#dg').edatagrid('destroyRow')">Destroy</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$('#dg').edatagrid('saveRow')">Save</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#dg').edatagrid('cancelRow')">Cancel</a>
    </div>

get_users.php (works)

<?php

include 'conn.php';

$rs = mysql_query('select * from schedule');
$result = array();
while($row = mysql_fetch_object($rs)){
    array_push($result, $row);
}

echo json_encode($result);

?>

destroy_user.php

<?php

$id = intval($_REQUEST['id']);

include 'conn.php';

$sql = "delete from schedule where id=$id";
@mysql_query($sql);
echo json_encode(array('success'=>true));
?>

Save_user.php

<?php

$date = $_REQUEST['date'];
$starttime = $_REQUEST['starttime'];
$endtime = $_REQUEST['endtime'];
$team1 = $_REQUEST['team1'];
$team2 = $_REQUEST['team2'];

require 'conn.php';

$sql = "insert into schedule(date,starttime,endtime,team1,team2) values('$date','$starttime','$endtime','$team1','$team2')";

mysql_query($sql);
echo json_encode(array(
    'id' => mysql_insert_id(),
    'date' => $date
    'starttime' => $starttime,
    'endtime' => $endtime,
    'team1' => $team1,
    'team2' => $team2
));

?>

update_user.php

$id = intval($_REQUEST['id']);
$date = $_REQUEST['date'];
$starttime = $_REQUEST['starttime'];
$endtime = $_REQUEST['endtime'];
$team1 = $_REQUEST['team1'];
$team2 = $_REQUEST['team2'];

include 'conn.php';

$sql = "update schedule set date='$date',starttime='$starttime',endtime='$endtime',team1='$team1',team2='$team2' where id=$id";

mysql_query($sql);
echo json_encode(array(
    'id' => $id,
    'date' => $date,
    'starttime' => $starttime,
    'endtime' => $endtime,
    'team1' => $team1
    'team2' => $team2
));
user1894814
  • 389
  • 1
  • 3
  • 12
  • 2
    open your web inspector and look for the responses of each script. whilst you're there, check for javascript errors. – Prisoner Apr 17 '13 at 23:49
  • Nothing jumps out at me except for the fact that you are not sanitizing data before using in your sql, and you should use mysqli and prepared statements http://j.mp/T9hLWi. I'm assuming that Save_user.php is supposed to be all lowercase and it's just a typo in your question... – Revent Apr 18 '13 at 00:06
  • 1
    Try changing `mysql_query($sql);` to `mysql_query($sql) or die(mysql_error());`. It might give you some insight as to if and why the queries are failing. – showdev Apr 18 '13 at 00:09
  • 1
    [Please, don't use `mysql_*` functions](http://stackoverflow.com/q/12859942/1190388) in new code. They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the red box? Learn about prepared statements instead, and use [tag:PDO] or [tag:MySQLi]. – hjpotter92 Apr 18 '13 at 00:21

1 Answers1

0

You used $_REQUEST but how you pass your data like id,date,... to PHP files. i am not familiar with jeasy-ui, but i guess you need to define something like columns in your jquery code to introduce data passed to PHP files.

Amir
  • 4,089
  • 4
  • 16
  • 28