Button to delete fullcalendar events-Celke

In the code below, when I click "Delete event" gives an error that we need to select the event (Event ID).

Desc

Code where events are loaded:

eventClick: function(event) {

                    $('#visualizar #id').text(event.id);
                    $('#visualizar #id').val(event.id);
                    $('#visualizar #title').text(event.title);
                    $('#visualizar #title').val(event.title);
                    $('#visualizar #start').text(event.start.format('DD/MM/YYYY HH:mm:ss'));
                    $('#visualizar #start').val(event.start.format('DD/MM/YYYY HH:mm:ss'));
                    $('#visualizar #end').text(event.end.format('DD/MM/YYYY HH:mm:ss'));
                    $('#visualizar #end').val(event.end.format('DD/MM/YYYY HH:mm:ss'));
                    $('#visualizar #color').val(event.color);
                    $('#visualizar').modal('show');
                    return false;

                },

Button:

<a class="btn btn-danger" type="button" href="deletar_evento.php">Excluir evento</a>

Deletar_event.php:

<?php
session_start();
include_once("conexao.php");
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
if(!empty($id)){
    $result_events = "DELETE FROM events WHERE id='$id'";
    $resultado_events = mysqli_query($conn, $result_usuario);
    if(mysqli_affected_rows($conn)){
        $_SESSION['msg'] = "<div class='alert alert-success' role='alert'>Evento excluído com sucesso!<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button></div>";
        header("Location: index.php");
    }else{

        $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'>Erro ao excluír evento!<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button></div>";
        header("Location: index.php");
    }
}else{  
    $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'>É necessário selecionar um evento!<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button></div>";
    header("Location: index.php");
}

Celke website: https://celke.com.br/artigo/como-editar-um-evento-no-fullcalendar-com-janela-modal-do-bootstrap

Author: Mario Uryu, 2018-04-11

2 answers

I think it is necessary to put the dots for him to join the string with the variable:

Addition:

$result_events = "DELETE FROM events WHERE id='$id'";

For this:

$result_events = "DELETE FROM events WHERE id='".$id."'";

If it is not post error please...

 1
Author: Mario Uryu, 2018-04-11 13:02:30

If you are familiar with Jquery, I don't quite know how you have the code but you can try like this

The <a> tag should have a id, like this: <a href="deletar_inscricao.php" id="tag_a_alterar">

$('#calendar').fullCalendar({
  eventClick: function(event) {
     $("#tag_a_alterar").attr("href", "deletar_inscricao.php?id="+calEvent.id);
  }
});

Thus, each time you click on an event, it will change href to the one you want to delete.

To set the id of an event, you will need to add an extra field when displaying that event.

If that's how I'm thinking, that's how the code is, just add a id

$('#calendar').fullCalendar({
  events: [
    {
      title  : 'event1',
      start  : '2010-01-01'
      id: '1'
    },
    {
      title  : 'event2',
      start  : '2010-01-05',
      end    : '2010-01-07'
      id: '2'
    }
  ]
});
 0
Author: I_like_trains, 2018-04-19 15:20:12