不能插入SQL更新
can't insert SQL updates
我使用jquery -ui填充数据网格。今天早些时候我已经开始工作了,然后决定移动一些不能工作的文件,最终回滚了我的更改。
不幸的是,现在它只填充表,并允许我删除行,但保存和插入似乎什么也不做。最糟糕的是,我知道这很简单,但我已经做了4个小时了,是时候问我没有看到什么了。
编辑
在save_user.php上的'date' => $date之后缺少逗号。我知道这很简单。谢谢你的帮助。
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(作品)
<?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
));
你使用$_REQUEST
,但你如何传递你的数据像id,date
,…到PHP文件。我不熟悉jeasy-ui
,但我猜你需要在你的jquery代码中定义一些像columns
的东西来引入传递给PHP文件的数据。
相关文章:
- 当客户端将两个按钮的javascript函数参数修改为相同时,SQL/PHP会更新多行
- 用sql数据库更新谷歌地图标记
- SQL生成的选择菜单,根据相关值更新文本框
- jQueryAjax SQL-如果我在多个用户上单击编辑,则Ajax会更新我单击的所有内容.不是最后一个点击
- 若data=0,则不更新(执行)表.(JavaScript/SQL)
- 单击按钮时更新表(SQL/JavaScript/HTML)
- 使用2个表单的SQL查询更新DIV
- 使用ajax和grails更新SQL数据库
- 从 SQL 数据库自动更新统计信息
- 新数据行上的 SQL 更新列
- 在不刷新页面的情况下更新 SQL 数据
- 如何更新在 SQL Server 数据库中发生某些更改时通过 jsp 显示的表内容
- 使用 SQL 信息更新选择下拉列表 (HTML)
- 使用 PHP 更新 SQL 数据库
- 我可以在我的JavaScript中包含php sql更新吗?
- 在javascript函数中更新sql
- 如何根据下拉选择框中的选择更新sql数据库中的特定记录
- 更新SQL Server数据库表编辑/更改
- 使用base64编码的数据更新SQL查询
- 使用 JavaScript 更新 SQL 记录