dora1989 2017-01-05 16:23
浏览 29
已采纳

无法使用php从数据库中删除某些行

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 &raquo;</a></p>
        </div>'; 
}

As you can see I gave it some simple style, and put it inside a div.

How note are being shown

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

  • 写回答

1条回答 默认 最新

  • dongqu9917 2017-01-05 16:30
    关注

    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:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow