[英]Call a php file from an other php file which has a html form in an echo?
我想通过单击表单中的按钮来删除mysql行。 问题是我在php中执行了cicyle,而html action属性未导航到另一个php页面中,该代码应在该页面中删除该行。 这是我的代码:
if ($result->num_rows > 0) {
echo "<table><tr><th>Vezetéknév</th><th>Keresztnév</th><th>Nemzetiség</th>
<th>Szülőváros</th><th>Találmányok száma</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["vezeteknev"]. "</td><td>" . $row["keresztnev"].
"</td><td>" . $row["nemzetiseg"] ."</td><td>"
. $row["szulovaros"]. "</td><td>". $row['talalmanyok']. "
</td> <td><form action='deleterow.php' method='post'>
<input type='submit' name='delete' value='".$row['id']."'/>
</form></td></tr>";
}
另一页(deleterow.php):
header('location:index.php');
include('DBConnection');
if(isset($_POST['delete'])){
$user = $_POST['delete'];
$delet_query = mysqli_query($conn,"DELETE FROM feltalalo WHERE id = '$user' ") or die(mysql_error());
}
如下更改代码:
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["vezeteknev"]. "</td><td>" . $row["keresztnev"].
"</td><td>" . $row["nemzetiseg"] ."</td><td>"
. $row["szulovaros"]. "</td><td>". $row['talalmanyok']. "
</td> <td><a href='deleterow.php?delete=".$row['id']."'>Delete</a></td></tr>";
}
deleterow.php
if(isset($_GET['delete'])){
$user = $_GET['delete'];
$delet_query = mysqli_query($conn,"DELETE FROM feltalalo WHERE id = '$user' ") or die(mysql_error());
}
我相信您想要实现的是能够使用链接删除条目,但是将其注册为发布请求。
为此,您需要像在链接之前那样生成一个表单
<form name="item_deleter_{YOUR_ID}" style="display:none;" method="post" action="{URL_FOR_DELETING}">
<input type="hidden" name="delete" value="{YOUR_ID}">
</form>
然后,在此之后,您将创建删除链接以具有onclick,该onclick使用javascript这样提交上述表单
<a href="#" onclick="document.item_deleter_{YOUR_ID}.submit(); event.returnValue = false; return false;">Delete</a>
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.