Php JQuery Ajax不更新记录
我有一些jqueryajax代码来更新记录,但它没有按预期工作 代码如下:Php JQuery Ajax不更新记录,php,jquery,Php,Jquery,我有一些jqueryajax代码来更新记录,但它没有按预期工作 代码如下: 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 ) {
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);
?>
函数更新_记录(){
$.ajax({
键入:“POST”//设置类型,然后$\u GET['id']或$\u POST['id']
url:“update_record.php”,
资料:{类别:“约翰”,图片:“波士顿”}
}).done(函数(msg){
警报(“保存的数据:“+msg”);
});
}; //端函数
然后是php
你需要
$id = $_REQUEST['id'];
我认为您在执行更新查询之前忘记了包含这一行。jQuery.com中的示例
我不明白你的查询返回了什么。
也许您需要选择whereid=$id代码>
// $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());
我知道你有:
$result = mysql_query("UPDATE mytable SET title = 'something' where id=$id");
我看不出你把$id
的值取在哪里,代码在哪里断开?是否调用了success函数?如果在浏览器中打开update_record.php会发生什么?你的HTML在哪里?我已将代码更新为你的代码,但没有更新,也没有保存消息。现在你的“数据”中没有“id”字段,因此没有$\u请求['id']
$result = mysql_query("UPDATE mytable SET title = 'something' where id=$id");