Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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="..https://waybackassets.bk21.net/img/delete.png" height='25' onclick="delete()" width='25' alt='delete'/></a></td>
share|improve this question

closed as off-topic by Jay Blanchard, G-Nugget, andrewsi, EdChum, greg-449 Mar 3 '15 at 8:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – andrewsi, EdChum, greg-449
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
And...!? (¬_¬)" . What is the problem? – bcesars Mar 2 '15 at 20:11
2  
Looks like you're going to need some JavaScript and PHP. Or do you have that already? – Jay Blanchard Mar 2 '15 at 20:12
    
What is the current behavior, and what is the expected behavior? – Tripp Kinetics Mar 2 '15 at 20:12
    
Well... shooting in the dark, your <a> tag seems wrong. Assuming this code is inside a <?php fix it with: <a href="../service/deleteModule.php?id=".$row['id']." "> – bcesars Mar 2 '15 at 20:14
    
public function delete($deletemodule){ return $this->moduleDao->deleteModule($deletemodule); } the onclick="delete()" function call doesn't get called, it is in a different file to the html code – Peter Connolly Mar 2 '15 at 20:18

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.

share|improve this answer

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="..https://waybackassets.bk21.net/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();
 }
?>
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.