PHP/HTML Add A remove button

前端 未结 2 1010
一整个雨季
一整个雨季 2021-01-26 02:32

I have the code below to retrieve rows from a database where the username column matches the base directory name:

$username =  basename(dirname(__FILE__));
$user         


        
相关标签:
2条回答
  • 2021-01-26 02:39
    echo "<a href='deletepage.php?id=$someid'>X</a>";
    

    create a page that with _GET['id'] parameter;

    And on that page i.e. deletepage.php?id=15

    $sql = "DELETE table FROM table WHERE id = ".(int)$_GET['id']
    
    mysql_query($sql);
    
    header("location: previoudpage.php");
    
    0 讨论(0)
  • 2021-01-26 02:50

    You could just add a submit button linking to the same page like

    while ($row = mysql_fetch_array($result)) { //loop
      extract($row);
      $html .= "<li><span style=\"font-family: verdana;\"><a href=\"{$link}\" target=\"_blank\">{$link}</a>  <form action=\"{$_SERVER["PHP_SELF"]}\" method=\"post\">
        <input type=\"hidden\" value=\"{link}\" name=\"Delete\" />
        <input type=\"submit\" value=\"Delete\" />
        </form></span> <span style=\"color:white;  font-family: verdana;\">- {$notes}</span></li>";
      }
    

    Then in your page do something like

    if (!empty($_POST["delete"])){
         $query = "DELETE FROM links where link = '{$_POST["Delete"]}'";
         mysql_query($query);
    }
    

    That's the basic idea of how I would do it

    0 讨论(0)
提交回复
热议问题