Fetching data in an AJAX page
In my AJAX page, I want to get data from the database. On my first page, I have del image
to delete the entry. I passed the cid file as "rmvfile" to the next page and took it out and displayed it on the second page.
On the first page, I pass the cf_id:
<img src="image/delete1.png" alt="delete" style="width:10px;height:10px" title="Remove" onclick="myFunction('.$fet['cf_id'].');">
function myFunction(cid) {
var rmvfile=cid;
if (confirm("Are you sure you want to Delete the file?") == true) {
if(cid!='') {
$.ajax({
type: 'post',
url: 'delete_cli_file.php',
data: {rmvfile: rmvfile},
});
}
}
}
I my second page which I am using:
<?php
include "config.php";
$s = $_POST['rmvfile'];
$sel = "select cf_id from client_file where cf_id='".$_POST['rmvfile']."'";
$sel1 = mysql_query($sel);
$sfet = mysql_fetch_assoc($sel1);
$file_name = $sfet['file_name']; //not fetched
$echeck = "delete from client_file where cf_id='".$_POST['rmvfile']."'";
$echk = mysql_query($echeck);
$del = "delete from client_file where file_name = '$file_name' ";
$del1 = mysql_query($del);
?>
$echeck = "delete from client_file where cf_id = '".$_POST['rmvfile']."'";
and $sel="select cf_id from client_file where cf_id='".$_POST['rmvfile']."'";
.
My problem is that the value is not selected in $sfet['file_name']
.
Please correct the sql query section in your code currently this
$sel = "select cf_id from client_file where cf_id='".$_POST['rmvfile']."'";
he should be
$sel = "select * from client_file where cf_id='".$_POST['rmvfile']."'";
As it now only fetches the cf_id, you didn't get any other fields.
source to share