-3

Undefined(Error), I am trying to pass variable but it fails. I also tried deleteItem(echo $filename;)

Code

foreach(glob('download/*.*') as $filename) {
deleteItem($filename)
}

Update

<a  class="btn mini green-stripe" onclick="deleteItem(<?php $filename ?>)" href="#">Load Item</a> 

PHP Parse error:  syntax error, unexpected '$result1' (T_VARIABLE)

I'm trying to pass variable into the ajax

Ajax

function deleteItem(link){
//Load select Items 
alert(link);
$.ajax({
    type: "POST", 
    url: "funcAjax.php",
    data: {"error":"0","deleteItem":link},
    dataType: 'json', 
    success: function(data) {
    if (data.error != 0) {
        // An error occurred on server: do something 
    } else {
alert(data.result1);

    }
}
});

}

Any idea how i can pass the variable which is the file name? I'm trying to pass it in and delete the image based on the name of the file but i cant seem to pass it though a variable

CodeGuru
  • 3,645
  • 14
  • 55
  • 99
  • Can you show us the function definition `deleteItem()`? – Amal Murali Oct 31 '13 at 14:26
  • It's not a function, It's pure php that is part of html – CodeGuru Oct 31 '13 at 14:30
  • 1
    Just a semantic note, I would recommend using `download/*` instead of `*.*`. – David Oct 31 '13 at 14:32
  • i Just try something similar to your code (with an `exec` function) and it works well under my `/tmp` directory... What error exactly shows? Did you try a `print_r(glob...)` or `var_dump`? – Sal00m Oct 31 '13 at 14:32
  • This question is a MEGA duplicate. Please use the search first. Error messages are explained here: [Reference - What does this error mean in PHP?](http://stackoverflow.com/q/12769982/367456) – hakre Oct 31 '13 at 14:35

1 Answers1

1

You need to return the $filename value, you can do it with <?=$filename?> or just echo the variable <? echo $filename; ?>

Change this:

<a  class="btn mini green-stripe" onclick="deleteItem(<?php $filename ?>)" href="#">Load Item</a> 

for this (EDITED: added quotes)

<a  class="btn mini green-stripe" onclick="deleteItem('<?= $filename ?>')" href="#">Load Item</a> 

This should work well

Sal00m
  • 2,938
  • 3
  • 22
  • 33
  • 1
    The next error you won't notice perhaps that fast but then some day your site has been hacked or something. You should better understand yourself why that error was there and how to fix it properly. It's a typical encoding issue. – hakre Oct 31 '13 at 14:44