Reputation:
In my AJAX-page I want to fetch data from a database. In my first page I have del image
to delete a record. I passed the file cid as 'rmvfile' to the next page and fetched and displayed them on the 2nd page.
In my first page I pass 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 2nd page I use:
<?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']."'";
are working.
My problem is that the value is not fetched in $sfet['file_name']
.
Upvotes: 3
Views: 92
Reputation: 300
You are not fetching file_name from mysql query
$sel = "select cf_id from client_file where cf_id='".$_POST['rmvfile']."'";
Change query to fetch file_name
$sel = "select cf_id,file_name from client_file where cf_id='".$_POST['rmvfile']."'";
Upvotes: 1
Reputation: 1759
Please correct the sql query section in your code currently it is
$sel = "select cf_id from client_file where cf_id='".$_POST['rmvfile']."'";
it should be
$sel = "select * from client_file where cf_id='".$_POST['rmvfile']."'";
As now it is fetching only cf_id, you didn't get the other fields.
Upvotes: 0
Reputation: 8168
You have not closed your image-tag properly and the quotes are not closed as well
<img src="image/delete1.png" alt="delete" style="width:10px;height:10px"
title="Remove" onclick="myFunction('.$fet['cf_id'].');">
And as stated by manikiran, check the if.condition.
Upvotes: 0
Reputation: 5388
Change your sql query to this
$myvar= $_POST['rmvfile'];
$sel="select cf_id from client_file where cf_id='$myvar'";
$sel1=mysql_query($sel);
$sfet=mysql_fetch_assoc($sel1);
$file_name=$sfet['file_name'];
Upvotes: 0
Reputation: 1
In your 2nd page
if($sel1=mysql_query($sel)) //Wrong verification
Use == rather than =
if($sel1==mysql_query($sel))
Upvotes: 0