当用户单击发送到其电子邮件的链接时。 删除数据库中的记录[关闭]

当用户单击发送到其电子邮件的链接时。 删除数据库中的记录[关闭]

问题描述:

The scenario : the user enter and order. A confirmation email is sent with a link to cancel the order. I would like to cancel the order by just clicking on the link without the user doing any other operation. is this possible?

场景:用户输入和订购。 发送确认电子邮件,其中包含取消订单的链接。 我想在没有用户进行任何其他操作的情况下点击链接取消订单。 这有可能吗? p> div>

Yes it is possible and here's how you do it. Let's say the following link is the one you sent to his/her email

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

In your PHP code,

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

[Edit] The order Id can be any value that you want to send as an email. For example,your code before sending the email might look like the following

$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 

Yes it is possible you have to send the url (link) of an ajax call in your email containing the id of order .The ajax call will make the change in your db.

For example in laravel I can write an ajax call in my routes file like this:

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

Now I can simply call this:

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