0

I am learning php and I am trying to learn how to show a sql table and be able to delete specific id's in a table.

In the code below, I am echoing a table called Project. My table is only showing Projects created by this user. All this works fine.

I would now like to let the user delete a specific project with a button shown next to each project.

<?php
    if( isset($_COOKIE['user_id_cookie']) ){
        $my_Query = "SELECT * FROM Project WHERE user_id=".$_COOKIE['user_id'];
        $result = mysqli_query($con, $my_Query);

            echo "<table id=\"table\"><thead class=\"thead\"><th>Project Name</th><th>Date Modified</th></thead>";
              while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
                 echo "<tbody><tr><td><a href=\"../index.php?ID_Project=".$row['ID_Project']."\">".$row['Name_Project']."</a></td><td class=\"date\">".$row['Date_Project']."</td></tr></tbody>";
              }
             echo "</table>";  

            mysqli_close($con);
     }
?>

I imagine it looking like this in the end:

||Project Name | Date Modified |        ||  
|| some name   |  some date    | Delete ||

I would like Something looking like this

enter image description here

How would I best go about this?

Adrien Boufflet
  • 141
  • 1
  • 10
  • 3
    Just a warning - it is unsafe to retrieve a userid from a cookie. Any user may pass any id in the cookie, thereby becoming any other user without difficulty, so this is instead typically handled by storing in `$_SESSION` where PHP manages a session cookie. It is also vulnerable to SQL injection the way it is now. Assuming it's int value, you can correct that using `intval($userid)` Beyond that, see [How can I prevent SQL injection in PHP](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) for examples using `prepare()/bind_param()/execute()` with MySQLi. – Michael Berkowski Mar 08 '15 at 13:05
  • Hello and Welcome to Stackoverflow. I have edited your question to stress the "problem" you're having. It's important to clearly state what exactly you want to solve / what your problem is. Additionally I have added a little ASCII-Drawing of a table in your question body. A "picture" is worth a thousand words they say. – Vogel612 Mar 08 '15 at 13:37
  • Hello vogel612. Thank you for pointing it out. I have edited my question and added a picture to show what I would like. – Adrien Boufflet Mar 08 '15 at 14:42

0 Answers0