Insert in database with JavaScript and php

1

I'm trying to insert into the database. The operation would be to give the button "Apuntarse" and that by inserting the user and the id of the hang-up to the database at the same time that the button is deactivated and the "Unplug" button is activated (so that there is more Of course, if one button is activated the other is deactivated)

I've tried a thousand things, the last test was with AJAX but between that I do not know how to use it well and I'm not sure it works ...

I enclose my code: -the_located.php

    <?php session_start(); ?>
    <!DOCTYPE html>
    <html>
    <head>
   <meta charset="utf-8">
<link rel="stylesheet" href="CSS/w3cssgeneral.css">
<link rel="stylesheet" type="text/css" href="CSS/estilo-ocio.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="javascript/apuntarse.js"></script>
<title>MEET A MATE</title>
</head>

<body class="color-fondo">
<div class="w3-content w3-sand">

<?php 
    require("codesincss/includes/comun/cabecera.php"); 
    require("codesincss/includes/comun/sidebarIzq.php"); 
    $nombre = $_GET['nombre'];
    $desc = $_GET['desc'];
    $local = $_GET['local'];
    $fini = $_GET['fini'];
    $org = $_GET['org'];
    $id = $_GET['id'];
    $tipo = 0;
?>

<div class="w3-row-padding w3-margin-top" id="contenedor-general">
        <div class="w3-card w3-container w3-white" id="sel-residencia">
            <h2 class='subt'><?php echo $nombre ?></h2>
            <p><?php echo $desc ?></p>
            <p><i class="fa fa-map-marker fa-fw w3-large w3-text-dark-blue"></i><?php echo $local; ?></p>
            <p><i class="fa fa-calendar fa-fw w3-large w3-text-dark-blue"></i><?php echo $fini; ?></p>
            <p><i class="fa fa-link fa-fw w3-large w3-text-dark-blue"></i><?php echo $org; ?></p>
            <div class ="w3-margin-bottom">
            <input type="button" id = "apuntarse" onclick = "myAjax()" class="w3-button w3-dark-blue" value="Apuntarse" />
            <input type="button" id = "desapuntarse" class="w3-button w3-dark-blue" value="Desapuntarse" />
            <p><i class="fa fa-users fa-fw w3-large w3-text-dark-blue"></i><?php echo "Participantes" ?> </p>

            <script>
            botones();
            </script>


            </div>


        </div>

    <div class = "w3-container w3-white w3-card w3-row-padding w3-margin-top" id="coment-residencia">
        <h4>Comentarios</h4>
            <?php
            require("codesincss/procesarComentarios.php");
            $lista = procesarComentarios::getComentarios("$id", 0);
            if (!empty(current($lista))) {
                for ($i=0; $i < count($lista); $i++) {
                    $comentario = $lista[$i]['Comentario'];
                    $valoracion = $lista[$i]['Valoracion'];
                    ?>

                    <div class="comentarios">
                        <p class="w3-margin-left">Valoracion: <?php echo $valoracion; ?> </p>
                        <p class="w3-margin-left" ><?php echo $comentario; ?> </p>
                    </div>
                    <?php
                }
            }
            ?>
    </div>


    <?php
    include("codesincss/includes/comun/comentario.php");
    if (isset($_SESSION["esAdmin"]) and  $_SESSION['esAdmin']){
        echo " <p><a id = 'detalles-general' href = 'borrarEvento.php?id=$id&tipo=$tipo'>Eliminar evento</a></p>";
        echo " <p><a id = 'detalles-general' href = 'modificarQuedada.php?id=$id'>Modificar evento</a></p>";
    }
    include("codesincss/includes/comun/sidebarDer.php"); 
    include("codesincss/includes/comun/pie.php"); 
    ?>
</div>

</body>
</html>

-apuntarse.js

    function botones(){

    var buttonD = $('#desapuntarse');
    var buttonA = $('#apuntarse');

    $(buttonD).attr('disabled','disabled');

    buttonA.click(function(){

        alert("Te has apuntado al evento");
       $(buttonA).attr("disabled", "disabled");
       $(buttonD).removeAttr("disabled");


     }
     );

    buttonD.click(function(){
        alert("Te has desapuntado del evento :( ");
        $(buttonD).attr("disabled", "disabled");
        $(buttonA).removeAttr("disabled");

     }
     );
     }

      function apuntarse(){
        $.ajax({
            type : "POST",
        url : "procesarApuntarse.php",
    });

  }

          function myAjax() {
         $.ajax({
        type: "POST",
       url: 'procesarApuntarse.php/ajax.php',
       data:{action:'call_this'},
       success:function(html) {
         alert(html);
       }

        });
     }

-programasrapuntarse.php

          <?php
        require_once "includes/config.php";
        function apuntarseAEvento(){
    $app = Aplicacion::getSingleton();
    $mysqli = $app->conexionBd();

    $id = $_GET['id'];
    $idUsuario = $_SESSION['idUser'];

    /*$app = Aplicacion::getSingleton();
    $mysqli = $app->conexionBd()*/;

    $sql = "INSERT INTO partecipantes (ID_Ocio, ID_Usuario, Nombre_Publico)
                VALUES ('$id', '$idUsuario', '1')";
    $mysqli->query($sql) or die ($mysqli->error. " en la línea ".(__LINE__));

    }
     ?>
    
asked by junemadrid 08.06.2018 в 11:34
source

0 answers