I am making a CRUD application in jquery and i have this problem in my application.To edit a record i am getting the id of the record successfully.
<a href="#" id="<?php echo $msg_id; ?>" class="update_btn">Edit</a>
I want to retrieve the id and that works.
$('.update_btn').live("click",function()
{
var ID = $(this).attr("id");
var dataString = 'msg_id='+ ID;
//alert(dataString);
$.ajax({
type: "POST",
url: "get-data.php",
dataType: 'json',
cache: false,
success: function(data){
//getData()
}
});
return false;
});
However,how can i use the retrieved id to
//get-data.php
include('db.php');
if($_POST['msg_id'])
{
$id=$_POST['msg_id'];
$id = mysql_escape_String($id);
$sql_in= mysql_query("SELECT msg FROM messages where msg_id='$id'");
$r=mysql_fetch_array($sql_in);
$msg=$r['msg'];
echo json_encode($msg);
}
return the data from the select query.Is this possible?.
You need to use
dataoption in your ajax request to send your id first:Now you will be able to get it in PHP with what you are doing eg
$_POST['msg_id']