1

I want to pass id value to ajax.rmvfile value echoed in this psge.I cant pass this to delete_emp_file.php page.

echo '<img src="image/delete1.png" id=".$ef." width="10" height="10" title="Remove" onclick="javascript:myFunction('.$fet['ef_id'].');">';

my script code

      <script>
       function myFunction(id)
       {   
       alert(id);
       var  rmvfile=id;
      //alert(rmvfile);
      $.ajax({
      type:'post',
      url:'hrms/delete_emp_file.php',
      data:{rmvfile: rmvfile},
      success:function(msg){
      if (msg.length> 0) {
      alert(msg); 
     }
    }
    });
  }
</script>

delete_emp_file.php

  echo $s=$_POST['rmvfile'];
  include "config.php";
  $echeck="delete from employee_file where ef_id='".$_POST['rmvfile']."'";
  $echk=mysql_query($echeck);
  $ecount=mysql_num_rows($echk);
  if($ecount>='1')
  {
    echo "file deleted";
 }
  • what error you are getting? – Kiren S Jan 02 '15 at 09:52
  • Missing single quotes on the `id` (or double quotes, same story). – briosheje Jan 02 '15 at 09:54
  • rmvfile is not send to next page. but alert is displayed with correct value –  Jan 02 '15 at 09:56
  • If you open up the developer tools (e.g. on Chrome or Firefox) you will find more detailed information about the reason why your request fails (turn on the network tab, failing requests usually show in red, you can click on it and inspect). Also, if the code in ``delete_emp_file.php`` is actual live code, then it is vulnerable to SQL injection: see this post on [so](http://stackoverflow.com/q/60174/870769) – sthzg Jan 02 '15 at 10:15
  • how to turn on network tag –  Jan 02 '15 at 10:17
  • Uncaught ReferenceError: $ is not defined trail.php?eid=1:95 Failed to load resource: the server responded with a status of 503 (Connection timed out) http://free.timeanddate.com/clock/i4fylv9t/n1763/fs15/tct/pct/ftb 4Uncaught ReferenceError: $ is not defined trail.php?eid=1:95 Failed to load resource: net::ERR_CACHE_MISS http://www.consultville.com/hrms/trail.php?eid=1 Failed to load resource: the server responded with a status of 503 (Connection timed out) –  Jan 02 '15 at 10:19
  • Then jQuery (`$`) is missing – Andreas Jan 02 '15 at 10:55

1 Answers1

-1

You need to add single quotes around the javascript parameter.

Otherwise, javascript parser will consider it as keyword or number.

Corrected code:

echo '<img src="image/delete1.png" id=".$ef." width="10" height="10" title="Remove" onclick="javascript:myFunction(\''.$fet['ef_id'].'\');">';
Pupil
  • 23,834
  • 6
  • 44
  • 66