删除包含查询的行并不起作用

时间:2014-07-25 12:37:19

标签: php mysqli html-table sql-delete

我找到了一种从表“动态”中删除行的方法,将每个要删除的按钮的id关联起来,这个id是从表中获取的。 将这行代码与每个按钮相关联:

"<td><form method='post' action='#'><a href=\"".$_SERVER['PHP_SELF']."?id=".$attivitaID."\" onClick=\"javascript:return confirm('Sei sicuro di voler cancellare questo prodotto?')\"><input type='button' value='Elimina' name='delete' id='back'></a></form></td>";

然后检查是否按下了它:

if(isset($_POST['delete'])&& isset($_GET['id']))
{
    $connessione = new MySQLi(HOST, USER, PASSWORD, DATABASE);

    $query = "DELETE FROM workpaper WHERE id = ?";

    $result = mysql_query($query);

    if (!$result)
    {
        die("Errore nella query $query: " . mysql_error());
    }

    mysql_close();

  }

但页面重新加载,没有进行任何查询,怎么办?

2 个答案:

答案 0 :(得分:0)

您的查询正在寻找看似符合的内容:

$query = "DELETE FROM workpaper WHERE id = ?";

也许您应该将$_GET['id']作为值添加到该子句中。

答案 1 :(得分:0)

变化:

$query = "DELETE FROM workpaper WHERE id = ?";

使用:

$query = "DELETE FROM workpaper WHERE id = ".$_POST['id'];


"<td><form method='post' action='".$_SERVER['PHP_SELF']."'><input type='hidden' name='id' value='".$attivitaID."\" /><input type='button' value='Elimina' name='delete' id='back'></form></td>";