0

I am trying to call a function within a php file that will fire a query to delete a row from a table and the database but can't seem to get it working

here is the button:

<td><a href="../service/deleteModule.php?id='.$row['id'].'"><img src="../web/img/delete.png" height='25' onclick="delete()" width='25' alt='delete'/></a></td>

2 Answers2

2

You could use an XMLHttpRequest in JavaScript.

myWebpage.html

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        // Row deleted successfully
        alert(xmlhttp.responseText)
    }
}
xmlhttp.open("GET", "deleteRow.php?rowWhichNeedsToBeDeleted=" + rowId, true);
xmlhttp.send();

myPHP.php

<?php
    $rowId = $_GET["rowWhichNeedsToBeDeleted"];
    Code to delete row...
    echo "Success";
?>

More information is at: http://www.w3schools.com/php/php_ajax_php.asp

Hope this helps.

Rajinikanth
  • 369
  • 1
  • 9
1

Call your php script by putting the button in a form and placing the php script in the form's action, which is called when the button is clicked.

<form method="post" action="delete.php">
  <td>
    <input type="image" name="delete" src="../web/img/delete.png"/>
 </td>
</form>

Update And call the specific function by using the isset method

<?php
 function delete()
 {
    function code here..
 }
if(isset($_POST['delete']))
 {
    delete();
 }
?>
serverNewbie
  • 55
  • 1
  • 9