表单会删除与example.php?id=7
等页面上的已过滤ID相关联的MySql数据库中存储的所有记录,并在成功删除记录后重定向到同一页面。
代码详情如下:
if ((isset($_POST['id'])) && ($_POST['id'] != "")) {
$deleteSQL = sprintf("DELETE FROM users WHERE id=%s",
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_example, $example);
$Result1 = mysql_query($deleteSQL, $example) or die(mysql_error());
$deleteGoTo = "example.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
$colname_deleterecord = "5";
if (isset($_GET['id'])) {
$colname_deleterecord = $_GET['id'];
}
mysql_select_db($database_example, $example);
$query_deleterecord = sprintf("SELECT id, user_name, email, address FROM users WHERE id = %s", GetSQLValueString($colname_deletetrecord, "int"));
$deleterecord = mysql_query($query_deleterecord, $example) or die(mysql_error());
$row_deleterecord = mysql_fetch_assoc($deleteecord);
$totalRows_deleterecord = mysql_num_rows($deleterecord);
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label>
<input type="submit" name="Delete Record" id="Delete Record" value="Delete Record" />
</label>
<input name="id" type="hidden" id="id" value="<?php echo $row_deleterecord['id']; ?>" />
</form>
如何在成功删除记录后,使用纯php语法在同一页面上显示表单操作状态消息(“Record deleted”)?
答案 0 :(得分:0)
您可以将动作消息存储到会话中..如果您使用任何MVC架构,则可以显示如下: -
$this->Session->setFlash('Record Deleted.');
试试这个..
答案 1 :(得分:0)
我终于解决了这个问题。
技巧是将查询字符串(键/值对)分配给标题位置变量,或者直接用它的关联值替换标题位置变量。
然后切换与函数和表单变量关联的查询字符串(键/值对)并用div包装div,成功删除后应在页面上显示表单操作状态消息。