From the beginning. I'm working on a small web application, using PHP. It consists in some kind of notepad, you can write a note and it'll save it for you. My problem is in deleting those notes, I can't figure out a way to delete the correct note. I query the database and show everything with a simple loop:
while($rows=mysqli_fetch_assoc($query_for_content)){
echo '
<div class="col-md-4">
<h2>' . $rows['title_text']. '</h2>
<p style="overflow-y:scroll; max-height:150px">' . $rows['txt_mensagem']. '</p>
<p style="color:#A0A0A0; font-size:90%;">' . $rows['date_creation']. '</p>
<p><a class="btn btn-secondary" id="row_table" data-toggle="modal" data-target="#open_modal_edit" role="button">Detail »</a></p>
</div>';
}
As you can see I gave it some simple style, and put it inside a div.
I've been thinking about my problem for some time, googled, asked friends, no luck.
The problem is that I can't figure out the correct query to delete the message. As shown in the picture I have some fields as "Title", "Message" and "Date of creation". I thought about using those field to create the query, but I can't access the fields.
I hope I didn't confuse you, and in case I did, please ask me so I can help you help me :D
You can simply create a new php script. Lets say delete.php
The content of the script may be:
session_start()
// Do your session checks and terminate script if user is not logged in....
// UID = lets say that uid is the primary key in your table
$delete_uid=$_GET['uid'];
$con = mysqli_connect(server,username,pass);
$con->query("delete from table_name where uid=$$delete_uid")
Just add a link to the script in your notepad passig uid of the note as Get parameter, for example:
<a href="delete.php?uid=212">Delete</a>
Alternatively you can also make an ajax call to the script. See https://www.tutorialspoint.com/ajax/what_is_xmlhttprequest.htm
You can read more about this here: