2014-12-19 23 views
0

該場景:用戶輸入並下單。 通過鏈接發送確認電子郵件以取消訂單。 我想通過點擊鏈接取消訂單,而無需用戶進行任何其他操作。這可能嗎?當用戶點擊發送到他的電子郵件的鏈接。來自數據庫的記錄被刪除

+0

是的,這是可能的。電子郵件中的鏈接與任何其他鏈接沒有區別。 – user4035 2014-12-19 06:03:04

+0

@ user4035我知道,但我怎麼做,當用戶點擊鏈接的行動。從數據庫中刪除它的唯一記錄 – 2014-12-19 06:04:24

回答

-1

是的,它是可能的,這裏的你是如何做到的。比方說,下面的鏈接是你發給他/她的電子郵件

http://www.example.com/?orderId=12567544356&cancel=1 

在你的PHP代碼中的一個,

if(isset($_GET['cancel']) && isset($_GET['orderId'])) 
{ 
    //you may also want to check the values.. 
    //then delete the record from the database table .. 
} 

[編輯] ID可以是你想發送的任何值順序作爲電子郵件。例如,發送電子郵件之前的代碼可能如下所示

$query = "SELECT orderId FROM Order WHERE user_id = $current_user_id"; 
// ... you will run the query 
$orderId = $row['orderId']; 
// then when you send your email, you will prepare the link the following way 
$cancelOrderLink = "http://www.example.com/?orderId=$orderId&cancel=1"; 
// send it 
+0

我可以發送一些值作爲一個PHP變量,例如 $ variable =「hello world」; 和鏈接是這樣的: http://www.example.com/?someVariable=$variable – 2014-12-19 06:11:19

+0

所以是的,你可以。檢查編輯的答案。 – 2014-12-19 06:30:27

1

是的,您可能需要發送包含訂單ID的電子郵件中的ajax調用的URL(鏈接).ajax調用將在您的數據庫中進行更改。

例如,在laravel我可以寫在我的路線Ajax調用文件是這樣的:

Route::get('/ajax-city', function() { 
    $countryId = Input::get('CountryId'); 
    $city = City::where('country_id', '=', $countryId)->get(); 
    return Response::json($city); 
}); 

現在我可以簡單地稱之爲:

http://website.com/ajax-city/2

+0

ajax調用的url?這是不可能的。 Ajax代表異步JavaScript和XML。沒有Ajax涉及鏈接。你也不想向取消訂單的用戶展示JSON – mplungjan 2014-12-19 07:00:53

相關問題