我有一些用来更新记录的jquery ajax代码,但它并没有像预期的那样工作。
代码如下:
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);
?>发布于 2012-05-16 20:47:17
来自jQuery.com http://api.jquery.com/jQuery.ajax/的示例
$.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;的位置
// $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());发布于 2012-05-16 20:52:05
我看到你有:
$result = mysql_query("UPDATE mytable SET title = 'something' where id=$id");我不明白你把$id的价值放在哪里
发布于 2012-05-16 20:47:04
您的需求
$id = $_REQUEST['id'];我想您在执行update查询之前忘记了包括这一行。
https://stackoverflow.com/questions/10618780
复制相似问题