【发布时间】:2015-09-25 21:13:53
【问题描述】:
我试图删除我的数据库中的一条记录。所以基本上我创建了一个包含我所有记录的表。现在我需要做的是,当我点击“DELETE”链接时,它会删除选中的记录行。
它是这样的:
所以基本上我这里有 3 页。
1.page.php
2.添加.php
3.删除.php
这是我的 page.php 文件:
<table border="1">
<thead>
<th>email</th>
<th>date</th>
<th>delete</th>
</thead>
<tbody>
<tr>
<?php
foreach($emails as $mail){ ?>
<td><?php echo $mail['email']; ?></td>
<td><?php echo $mail['date']; ?></td>
<td><?php echo "<a href='delete.php?id=". $mail['id']. "'>DELETE</a>"; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
这是我的 add.php 文件:
<?php
require("new-connection.php");
session_start();
$email = $_POST['email'];
if(empty($_POST['email']) AND (filter_var($email, FILTER_VALIDATE_EMAIL) === false))
{
$_SESSION['message'] = "email cannot be blank";
}else{
$query = "INSERT INTO email_tbl (email, date)
VALUES('$email', NOW())";
$insertEmail = run_mysql_query($query);
if(run_mysql_query($query))
{
$_SESSION['message'] .= "New RECORD has been added correctly!";
}
else
{
$_SESSION['message'] .= "Failed to add new Interest";
}
}
header('Location: email.php');
?>
到目前为止,这是我的 delete.php 文件:
<?php
require("new-connection.php");
session_start();
$query = "DELETE FROM email_tbl
WHERE id={id} LIMIT 1";
$deleteEmail = run_mysql_query($query);
if(run_mysql_query($query))
{
$_SESSION['message'] .= "RECORD has been DELETED correctly!";
}
else
{
$_SESSION['message'] .= "Failed to DELETE RECORD";
}
header('Location: email.php');
?>
所以现在当我点击删除链接时,它必须实时删除按钮。任何想法?
【问题讨论】:
-
改用一个按钮并将每个按钮包装在一个带有隐藏字段的表单中,或者您甚至可以使用 iframe 和 $_GET 或 ajax。这个 id={id} 不行。
-
什么是实时,无需重新加载页面?
-
这是什么? run_mysql_query()