This is my back end, which seeks to update the user's nickname
<?php
session_start ();
include_once 'conexion.php';
$respuesta = array();
if( empty($_REQUEST['nick-nuevo']))
{
$respuesta['mensaje'] = 'Nuevo nick, vacio';
}
else
{
$nicknuevo = $_REQUEST['nick-nuevo'];
$sql = 'UPDATE Usuario SET nick = "$nicknuevo" WHERE id = "$_SESSION["id"]"';
mysqli_query ($conn, $sql);
}
Investigating in StackOverflow, I came across this This however I do not think it has any variable undefined, try doing it with this
$sql = "UPDATE Usuario SET nick = '". $nicknuevo. "' WHERE id = '".$_SESSION['id']"'";
To see if it changed something and it tells me the following error
[Parse error: syntax error, unexpected '"'" '(T_CONSTANT_ENCAPSED_STRING)] that according to this I have my bad quotes link but from my perspective everything seems to be in order, I do not see any error.
ANNEX
<?php
include_once 'header.php'
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function() {
$(document).on('click', '#update-btn', function (e) {
e.preventDefault();
var obj = {
'nick-nuevo': $('#nick-nuevo').val().trim(),
};
$.ajax({
url: 'back_update.php',
method: 'POST',
data: obj,
success: function ( respuesta ){
alert( respuesta.mensaje );
},
error: function( e, err, error ){
//Añadimos un nodo de error, por si pasa algo en el servidor, esto lo vamos a ver en la consola de depuración
console.log(e, err, error);
}
})
});
})
</script>
<div class="main-wrapper">
<form id="update-form" class="signup-form" method="POST">
<h2>Actualizar</h2>
<input id="nick-nuevo"type="text" name="nick_nuevo" placeholder="nick nuevo" required> </input>
<button id="update-btn"type="submit" name="submit" value="actualizar">
Actualizar
</button>
</form>
<?php
include_once'footer.php';
?>