简体   繁体   English

PHP:在最后一列中添加删除按钮以删除表行

[英]PHP : add a delete button in last column to delete a table row

I have a table displayed in HTML. 我有一个以HTML显示的表格。 I want to add a button delete in the last column to remove the considered line of the table. 我想在最后一列中添加按钮delete ,以删除表中考虑的行。 Thus, I create a form in my last column, with a hidden value, which is id (= primary key of my table entry), to pass id, through a POST method, in another page to launch an DELETE SQL query. 因此,我在最后一列中创建了一个表单,该表单的隐藏值是id (=表条目的主键),以便通过POST方法在另一个页面中传递ID,以启动DELETE SQL查询。 The below code is not working : 下面的代码不起作用:

<form action="delete_facture.php" method="post">
            <input type="hidden" name="id2" value="<?php $donnees['id'] ?>"/>
            <input type="submit" value="delete"/>
</form>

Than the delete_facture.php is the following : 比delete_facture.php是以下内容:

<?php
// Connexion à la base de données
try
{
$bdd = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$req = $bdd->prepare('DELETE FROM factures WHERE id= :id2');
$req->execute(array(
                    ':id2'=>$_POST['id2']
                    ));
header('Location: index.php');
?>

What's wrong in my code ? 我的代码有什么问题? Thank you. 谢谢。

put echo , then only it will assign the value in the textbox. 放置echo ,那么只有它会在文本框中分配值。 Otherwise you will get empty value. 否则,您将获得空值。 Try this, 尝试这个,

<input type="hidden" name="id2" value="<?php echo $donnees['id'] ?>"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM