大家好,我有问题,与我的形式删除用户,当我提交按钮什么都没有发生什么是问题,一切工作的数据库,当我获取信息,他们来了,但当我点击删除什么都没有发生
<?php
$host ="localhost";
$dbname ="justnew";
$u_name="root";
$u_pass="youcef02";
echo'
<table border="1px solid #efefef" width="42%">
<tr>
<th>ID</th>
<th>Name</th>
<th>Password</th>
<th>DELETE</th>
</tr>
';
try{
$Conn = new PDO("mysql:host=$host;dbname=$dbname",$u_name,$u_pass);
}
catch(PDOEXCEPTION $e){
echo'There is a prblm' .$e->getMessage();
}
$sql = "SELECT * FROM addu";
$result = $Conn->query($sql);
while($row = $result->fetch(PDO::FETCH_OBJ)) {
echo"
<tr>
<td>" .$row->u_id."</td>
<td>" .$row->u_name."</td>
<td>" .$row->u_pass."</td>
<td><button name='dlt'><a href='attribute.php?
type=dlt&u_id=".$row->u_id."' name='dlt'>DELETE</a></button></td>
</tr>
";
}
if($_GET['type'] == ['dlt']){
$id = intval ($_GET['u_id']);
$Dsql = "DELETE * FROM `addu` WHERE `u_id` ='".$id."'";
$Dresult = $Conn->exec($Dsql);
}
?>
1条答案
按热度按时间23c0lvtd1#
看到没有人想张贴这个答案,我提交以下。
如前所述:
if($_GET['type'] == ['dlt'])
无效。支架周围dlt
需要删除,并且会引发语法错误。if($_GET['type'] == 'dlt')
但是,您应该检查get数组是否为set/not empty,因为如果没有它,也会抛出一个未定义的索引警告,在您的系统上设置了错误报告。或
那么您的查询的删除部分也是无效的。
应改为:
https://dev.mysql.com/doc/refman/5.7/en/delete.html
星号仅对select语句有效:
https://dev.mysql.com/doc/refman/5.7/en/select.html
使用(pdo)错误处理后,您肯定会得到一个语法错误:
https://php.net/manual/en/pdo.error-handling.php
现在这个钻头可能会产生不利影响:
最好(通常)把这些都放在一行:
增加的空间可以在这里计算。
注意:您使用了
name
属性两次。如果上述方法失败,则
<a href></a>
不应该在房间里<button></button>
,只需使用<a href></a>
.