首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JQuery Ajax不更新记录

JQuery Ajax不更新记录
EN

Stack Overflow用户
提问于 2012-05-16 20:42:29
回答 3查看 372关注 0票数 1

我有一些用来更新记录的jquery ajax代码,但它并没有像预期的那样工作。

代码如下:

代码语言:javascript
复制
    function update_records() {
    $.ajax({
  type: "POST", // Set the type then $_GET['id'] or $_POST['id']
  url: "update_record.php",
  data: { category: "John", image: "Boston" }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

}; //end function


Then the php

<?php 

  $id = $_REQUEST['id'];


  include 'config.php';


  $result = mysql_query("UPDATE mytable SET title = 'something' where id=$id"); 
  $result = mysql_query("SELECT * FROM mytable WHERE id = '$id'");             
  $array = mysql_fetch_row($result);  

?>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-05-16 20:47:17

来自jQuery.com http://api.jquery.com/jQuery.ajax/的示例

代码语言:javascript
复制
$.ajax({
  type: "POST", // Set the type then $_GET['id'] or $_POST['id']
  url: "some.php",
  data: { name: "John", location: "Boston" }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

我无法理解您的查询返回的是什么。也许你需要选择id = $id;的位置

代码语言:javascript
复制
 //  $id = $_POST['id'] or $_GET['id']  Where is $id??? 
  $result = mysql_query("UPDATE mytable SET title = 'something' where id=$id"); 
  $result = mysql_query("SELECT * FROM mytable WHERE id = '$id'");             
  $array = mysql_fetch_row($result);    


 //You can use mysql_error() function to see the error.
 $result = mysql_query("UPDATE mytable SET title = 'something' where id=$id") or    die(mysql_error());
票数 1
EN

Stack Overflow用户

发布于 2012-05-16 20:52:05

我看到你有:

代码语言:javascript
复制
$result = mysql_query("UPDATE mytable SET title = 'something' where id=$id");

我不明白你把$id的价值放在哪里

票数 1
EN

Stack Overflow用户

发布于 2012-05-16 20:47:04

您的需求

代码语言:javascript
复制
$id = $_REQUEST['id'];

我想您在执行update查询之前忘记了包括这一行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10618780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档