Reputation: 49384
I have some jquery ajax code to update a record but it's not working as expected.
Here is the code:
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);
?>
Upvotes: 1
Views: 380
Reputation: 534
Example from 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 );
});
I can't understand what your query returns.
Maybe you need to select where 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());
Upvotes: 1
Reputation: 1694
I see you have:
$result = mysql_query("UPDATE mytable SET title = 'something' where id=$id");
I don't see where you take the value of $id
Upvotes: 1
Reputation: 2623
u need
$id = $_REQUEST['id'];
I think you forgot to include this line before executing the update query.
Upvotes: 0