This is translated, I'm sorry if there's something wrong.
I have a problem and it is that when I insert the name of the session it tells me that it is undefined. I did tests inserting the manual username and if everything works.
https://i.stack.imgur.com/WgeB3.jpg
<? php
session_start ();
echo var_dump ($ _SESSION);
?>
The first thing that the php has is this, as you can see the var_dump correctly shows the user's name.
The message of (username) is not defined in the console.
I'm doing it with a modal.
The textbox is inserted correctly, I just need the name of the session that inserts it. The database works correctly (I tried inserting the parameters manually)
As you can see with var_dump correctly shows the user name of the session. Also insert the content of textarea well, just need to insert the name of the session
<script>
$(inicializarEventos);
function inicializarEventos(){
$("#insertar").click(insertarSugerencia);
}
function insertarSugerencia(){
var nombreUsuario= <?php echo $_SESSION['usuario']?>;
var textoSugerencia=$("#textoSugerencia").val();
console.log(nombreUsuario,textoSugerencia);
$.ajax({
url:"bd/bd.php",
method: "POST",
data:{nombreUsuario:nombreUsuario,textoSugerencia:textoSugerencia},
dataType:"JSON",
success:function(){
alert ("Sugerencia enviada correctamente");
$("#modal1").modal("hide");
}
});
}
</script>