0

I'm having some trouble getting my HTML and php to work together.

I've made a onClick that should run a PHP function i have in the top of the PHP file. But every time i click it, it says: ReferenceError: deleteSub is not defined. Can someone tell me what I've done wrong?

HTML:

<?php
                if(mysql_num_rows($sql_select_delete) > 0){
                     while($row = mysql_fetch_assoc($sql_select_delete)){
                         ?><div class="abo_box">
                           <label class="abo_navn" id="<? echo $row["id"]; ?>"><? echo $row['abo_name'];  ?></label>
                           <label class="delete" onclick="deleteSub();">Delete</label>
                         </div>
                         <?php
                     }
                }
           ?>

PHP:

function deleteSub(){
      echo "deleted";
 }
Patrick R
  • 1,949
  • 3
  • 32
  • 58

2 Answers2

2

You can't call directly a PHP code like this What you can do is to create a javascript function and you need to use Ajax witch will send a request to your re server and here you can call your PHP function Remember : PHP is server side code and HTML, JS is client side code, the only way to make them work together is using HTTP requests.

Anas EL KORCHI
  • 2,008
  • 18
  • 25
0

you could do something like this. But to use server side information you should use AJAX and http requests. This example is just for changing DOM elements.

 <p id="demo" onclick="myFunction()">Click me to change my text color.</p>

<script>
function myFunction() {
    document.getElementById("demo").style.color = "red";
}
</script>
Markvds
  • 137
  • 10