In demand


Wednesday, September 2, 2015

The worst of stackoverflow - question/32352587 is a  site that  tries to  help developers and programmers. Unfortunately it frequently fails miserably at the task due to restrictions over moderation. Sometime the model is just a poor fit that does not help or teach  new comers  and it  bores  advanced developers to death.  This is a chronicle of some of the websites most glaring problems.

How can I delete a row from a database with a button, displayed using php?

I would like to be able to delete a row using the delete-button I display at the end of each row.
I need two queries to delete a person from my database completely since I have a n-m relationship
 between Persons and Functions.

The queries are as follows:
delete from Persons_Functions where `Person ID` = '1'; 
delete from `Persons` where `Person ID` = '1';
I would like to implement these queries using the delete-button provided in the actual code,
how can I do this?

        $query = "SELECT p.`Person ID`, p.`First Name`, p.`Last Name`, p.Gender, p.`Date Of Birth`, p.Email, p.`Phone Number`, c.Region, c.Country, p.`Delegation ID`
        FROM Persons as p, Chapters as c
        WHERE c.`Chapter ID`=p.`Chapter ID`
        ORDER BY p.`Delegation ID";

        $result = mysql_query($query) or die($dberror3 . mysql_error());
        $row = mysql_fetch_assoc($result);
        foreach ($row as $col => $value) {
            echo "<th>";
            echo $col;
            echo "</th>";

    mysql_data_seek($result, 0);
    while ($row = mysql_fetch_assoc($result)) {
            foreach($row as $key => $value){
                echo "<td>";
                echo $value;
                echo "</td>";
            <td><button type="button">Delete</button></td>
        <?php } ?>

where is javascript –  Satender K 12 mins ago

1 Answer

I would use JavaScript and Ajax here.
  1. Make a Html-button with an onclick function like delete_user();
  2. delete_user() calls a .php file to validate the rights and execute some mysql-delete promts.
  3. The .php file returns a boolean to the JavaScript.
  4. You could catch that boolean up and inform the user about the result.

Unfortunately I don't know how to write Javascript yet. Is what I'm trying to do do-able using only PHP and MySQL? –  Tom 1 min ago

Today's Links

Post a Comment

Print this!