dongren4147 2013-07-18 23:15
浏览 134

从数据库中删除选定的行

I would like to delete a row from mysql database. The row I would like to delete is the 'selected item' in the combobox.

My code so far:

    $sql = "SELECT data_id FROM projects";
    $result = mysql_query($sql);

    echo "<select name='data_id '>";
    echo "<option selected>Please select...</option>";
    while ($row = mysql_fetch_array($result)) 
    {
        echo "<option value='" . $row['data_id '] . "'>" . $row['data_id'] . "</option>";
    }
    echo "</select>";

    ?>
    <tr><td><input type="submit" name="delete" value="Delete" id="delete"></td></tr></tr></table>
    <?php
     //delete selected item from projects table...
    ?>

The combobox is showing all the items from my projects table. When I select an item, then click on 'delete' I would like to delete that item from the table.

Any help will be appreciated.

enter image description here

  • 写回答

3条回答 默认 最新

  • douyue8191 2013-07-18 23:48
    关注

    Your logic should be:

    At top of script before html, check for POST values from form if they exist, use the variables to delete the appropriate database value use header('location') back to the same page to reload the page (so value is removed from form below)

    where you have your select box, make that a form, action= same page, method = post

    tomorrow I will post example code if you have not worked it out by then

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度