的建議使用JavaScript都很好,但知道這不是唯一的選擇。
下面是一個工作流程,可以爲您工作,只使用PHP和每個操作的不同頁面請求。
/users.php?id=5
<h1>Viewing <?php $_GET['id'] ?></h1>
...
<a href="/users.php?id=5&action=edit">Edit this user</a>
/users.php?id=5 &行動=編輯
<h1>Editing <?php $_GET['id'] ?></h1>
...
<a href="/users.php?id=5">Cancel edits</a>
<a href="/users.php?id=5&action=save">Save changes</a>
<a href="/users.php?id=5&action=deleteConfirmation">Delete this user</a>
/users.php?id= 5 & action = deleteConfirmation
<h1>Are you sure you want to delete <?php echo $_GET['id'] ?></h1>
<a href="/users.php?id=5">Cancel</a>
<a href="/users.php?id=5&action=delete">Confirm</a>
/users.php?id=5 &行動=刪除
$sql = "DELETE FROM users ..."
mysqli_query($sql) ...
header('Location: /users.php?action=deleteSuccessful');
users.php可能看起來像這樣(僞)
switch ($_GET['action']) {
case 'edit':
<h1>Editing using...</h1>
<form> ...
break;
case 'save':
mysqli_query('UPDATE USERS SET ...');
header('Location: ...');
break;
case 'deleteConfirmation':
<h1>Are you sure you want to delete user 5</h1>
<form> ...;
break;
case 'delete':
mysqli_query('DELETE FROM USERS ...');
header('Location: ...');
break;
default:
<h1>Viewing User 5</h1>
...
break;
}
經過對照測試的CR UDs
你可能想看看RESTful APIs。有一些約定用於爲URL設置資源,然後使用不同的HTTP動詞與資源進行交互。
這是一個基本速成班的理論用戶資源
http url description
GET /users display all users
POST /users create a new user
GET /users/1 display user with id: 1
GET /users/1/edit display the edit user page
PUT /users/1 replace all the fields for user id: 1
PATCH /users/1 update 1 or more fields for user id: 1
DELETE /users/1 remove user with id: 1
這通常是通過JavaScript完成。你創建一個請求確認的彈出窗口,然後向服務器發送一個AJAX請求;讀取服務器響應並通知用戶有關成功或失敗的操作。 –
按下按鈕客戶端,彈出詢問是否確定。如果確認,處理。如果沒有,不要。簡單 –
不使用HTTP,至少不是很容易。你最好打賭它有一個預先刪除屏幕/模式,其中說「你確定嗎?」是/否,然後導致上述屏幕。 – Farkie