Guest User

Untitled

a guest
May 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. session_start();
  2.  
  3. if (isset($_SESSION['user'])) {
  4. $status = 'ERROR';
  5. $validator = new Validator();
  6. $validator->add('id:Product_Id', 'required');
  7. $validator->add('id:Product_Id', 'integer');
  8.  
  9. if ($validator->validate($_POST)) {
  10. try {
  11. Closet::create([
  12. 'user_id' => $_SESSION['user']['id'],
  13. 'product_id' => $_POST['id'],
  14. ]);
  15. $status = 'OK';
  16. } catch (QueryException $e) {
  17. Log::logError($e->getMessage());
  18. }
  19. }
  20.  
  21. header('Type-Content: application/json');
  22. echo json_encode(['status' => $status]);
  23. }
  24. else {
  25. header('Location: pantalladelogin.php');
  26. }
  27.  
  28. <a onclick="addProduct(1)">
  29. <i class="material-icons">add</i>
  30. </a>
  31.  
  32. function addProduct (id) {
  33. const formdata = new FormData()
  34. formdata.append('id', id)
  35.  
  36. fetch("/addproduct.php", {
  37. method: 'post',
  38. body: formdata
  39. }).then(function(response) {
  40. console.log(response)
  41. return response.text()
  42. }).then(function(data) {
  43. console.log(data)
  44. });
  45. }
  46.  
  47. Response { type: "basic", url: "http://localhost/pantalladelogin.php", redirected: true, status: 200, ok: true, statusText: "OK", headers: Headers, bodyUsed: false }
  48.  
  49. var sesion = <?=json_encode($_SESSION['identificadorSesion'])?>;
Add Comment
Please, Sign In to add comment