0

On my website I've a htmlt table generated with data from a data base. Next to each row I put a Delete Button but I don't know how to get data from the row to pass in a php function to delete the record from the database.

HTML Table

I put my data in table like this so I tried to pass data in onClick:

<?php 
                    $counter = 0;
                    foreach($result as $key => $value): ?>
                        <tr id='row<?php echo $counter?>'>  
                            <td><?php echo $value['Nom']; ?></td>
                            <td><?php echo $value['Prenom']; ?></td>
                            <td><?php echo $value['Adresse']; ?></td>
                            <td><?php echo $value['Datedenaissance']; ?></td>
                            <td><?php echo $value['Numerodetelephone']; ?></td>
                            <td>
                         <button type="button" value="delete" onclick="(<?php echo $value['Nom']; ?>,<?php echo $value['Prenom']; ?>);" class='btn btn-danger glyphicon glyphicon-remove'></button>
                            </td>
                        </tr>
                <?php 
            $counter++;
            endforeach; 
            ?> 

After I get data in JS function and I do a php echo but it doesn't work.

    function deleteRow(nom,prenom) {

  <?php echo supprimermembre(nom,prenom);?>

}
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Have you tried to inspect the generated markup? Your `onclick` attribute looks strange to me – Nico Haase Jun 25 '18 at 08:33
  • 2
    You may wanna look at this; https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming/ – Can O' Spam Jun 25 '18 at 08:35
  • onClick is like this : onclick="deleterow(,)",i modified it just before posting the question –  Jun 25 '18 at 08:37
  • ok thanks for the link, i understand better now :) . But i still dont get how can i do to delete the row in my databse :/ –  Jun 25 '18 at 08:42
  • 1
    You need to create a form, post to that form with your data, and in the PHP that loads the page, delete the record, you can delete from the page at run time, but not the database (unless you use AJAX), that must be done on server – Can O' Spam Jun 25 '18 at 08:45
  • `function deleteRow(nom,prenom) { }` - other errors notwithstanding, that is *never* going to work. See [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – CD001 Jun 25 '18 at 08:57
  • Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – CD001 Jun 25 '18 at 08:59
  • guys, i understand that it wont work but can you please help me find a way to delete the record corresponding to the table row ? –  Jun 25 '18 at 09:47
  • Hi @AlexandreHuvenne , It is very simple concept to delete record .. JUst you need send id to delete function we have wrote .. That can achieve by using jquery or simple java script ..Can you inbox to me you code ... – Dibya Krushna Das Jun 25 '18 at 10:37
  • @DibyaKrushnaDas you don't have a private inbox on StackOverflow...and anyway this is a public forum...the code can be provided in public, and so can your answer. That way everyone can learn - and you can earn upvotes :) – ADyson Jun 25 '18 at 14:53
  • @AlexandreHuvenne here is the basic idea: in your JavaScript code you can make an AJAX request to the server to call a specific PHP script which deletes the record. You pass the correct ID to it as a parameter. When you get confirmation of a successful delete back from the server, you can use some more simple JavaScript to remove that row from your HTML table. It's a very common scenario - if you research a bit you can probably find previous questions on SO, and other tutorials, examples, resources etc which will point you in the right direction with this kind of task – ADyson Jun 25 '18 at 14:54

0 Answers0