表單會刪除存儲在MySql數據庫中的所有記錄,例如example.php?id=7
等頁面上與過濾後的ID相關聯的記錄,並在成功刪除記錄時重定向到相同的頁面。如何在成功刪除後顯示錶單操作狀態消息?
代碼的細節如下:
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語法在同一頁上成功刪除?
what do you mean with「on the same page」?在我看來,你在刪除後重定向 – 2012-03-26 09:05:11
成功的表單操作'header(sprintf(「Location:%s」)後頁面被重定向到同一頁面,$ deleteGoTo));' 'action =「<?php echo $ _SERVER ['PHP_SELF'];?>'。 – polarexpress 2012-03-26 10:59:57