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']

.

+3


source to share


6 answers


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.

0


source


try



$del1 = mysql_query( $del ).mysql_error();

      

+1


source


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, filename from client_file, where cf_id = '". $ _ POST ['rmvfile']. "'";

+1


source


On your second page

if($sel1=mysql_query($sel)) //Wrong verification

      

Use ==, not =

if($sel1==mysql_query($sel))

      

0


source


You haven't closed your image shortcut and the quotes are not closed either

<img src="image/delete1.png" alt="delete" style="width:10px;height:10px"
title="Remove" onclick="myFunction('.$fet['cf_id'].');">

      

And as manikiran pointed out, check if.condition.

0


source


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']; 

      

0


source







All Articles