Edited: With trim I "fixed" the spaces (I would like to know why the values are arriving with spaces: /) but I could not fix the problem with the +
symbol.
I will formulate my question that I asked previously like this:
I have a table and I want to edit data for that I transform the row of a table into a form, then I get the data that is at that moment in the form and I save it in variables. Then the data that the user modifies I keep in other variables and both I send them by post to a php using ajax. My problem is that when I receive the variables I have 2 problems:
F
, F+
or F++
. The problem is that when you receive the string you receive only the F
does not save the symbols +
so the query should fail. Has anyone had a similar problem or does it occur to him to solve it? in advance thank you very much
PHP queries:
<?php
$especiee = $_POST["especiee"];
$generoo = $_POST["generoo"];
$familiaa = $_POST["familiaa"];
$calidadd = $_POST["calidadd"];
$tamañoo = $_POST["tamañoo"];
$ciudadd = $_POST["ciudadd"];
$comentarioo = $_POST["comentarioo"];
$precioo = $_POST["precioo"];
$especie = $_POST["especie"];
$genero = $_POST["genero"];
$familia = $_POST["familia"];
$calidad = $_POST["calidad"];
$tamaño = $_POST["tamaño"];
$ciudad = $_POST["ciudad"];
$comentario = $_POST["comentario"];
$precio = $_POST["precio"];
$conexion=mysqli_connect('localhost','root','','shells');
$consulta="update shell set especie='$especiee',
genero='$generoo',familia='$familiaa',calidad='$calidadd',tamano='$tamañoo',
ciudad='$ciudadd',comentario='$comentarioo',precio='$precioo' where especie='$especie'
and genero=$'$genero'and familia='$familia'and calidad='$calidad'and tamano='$tamaño'and
ciudad='$ciudad'and comentario='$comentario'and precio='$precio' "
$request=mysqli_query($conexion,$consulta);
if($request) echo "funciona";
else echo "error";
?>
Here is the data:
<?php
$conexion=mysqli_connect('localhost','root','','shells');
$request=mysqli_query($conexion,"select especie, genero,familia,calidad,tamano,ciudad,comentario,precio from shell where habitad='land' order by familia,genero,especie ");
while($prueba=$request->fetch_assoc()){
?>
<tr class="info">
<td><?php echo $prueba['familia'] ; ?> </td>
<td><?php echo $prueba['genero'] ; ?> </td>
<td><?php echo $prueba['especie'] ; ?> </td>
<td><?php echo $prueba['calidad'] ; ?> </td>
<td><?php echo $prueba['tamano'] ; ?> </td>
<td><?php echo $prueba['ciudad'] ; ?> </td>
<td><?php echo $prueba['comentario']; ?> </td>
<td><?php echo $prueba['precio'] ; ?> </td>
<td><input type=submit name="editar" value="Editar" onclick="transformarEnEditable(this)" class="btn btn-primary"> </input> </td>
<td><input type="submit" name="eliminar" value="Eliminar" class="btn btn-danger"></input></td>
</tr>
<?php } ?>
And here I have the function that transforms the table into a form
function transformarEnEditable(nodo){
//El nodo recibido es SPAN
if (editando == false) {
editando = "true";
var nodoTd = nodo.parentNode; //Nodo TD
var nodoTr = nodoTd.parentNode; //Nodo TR
var nodosEnTr = nodoTr.getElementsByTagName('td');
especie = nodosEnTr[0].textContent;
genero = nodosEnTr[1].textContent;
familia = nodosEnTr[2].textContent;
calidad = nodosEnTr[3].textContent;
tamaño = nodosEnTr[4].textContent;
ciudad = nodosEnTr[5].textContent;
comentario = nodosEnTr[6].textContent;
precio = nodosEnTr[7].textContent;
Editar = nodosEnTr[8].textContent;
nuevoCodigoHtml = '<td><input type="text" name="especie" id="especie" value="'+especie+'" size="17"></td>'+
'<td><input type="text" name="genero" id="genero" value="'+genero+'" size="10"</td>'+
'<td><input type="text" name="familia" id="familia" value="'+familia+'" size="10"</td>'+
'<td><input type="text" name="calidad" id="calidad" value="'+calidad+'" size="5"</td> '+
'<td><input type="text" name="tamaño" id="tamaño" value="'+tamaño+'" size="5"</td> '+
'<td><input type="text" name="ciudad" id="ciudad" value="'+ciudad+'" size="10"</td> '+
'<td><input type="text" name="comentario" id ="comentario" value="'+comentario+'" size="20"</td> '+
'<td><input type="text" name="precio" id="precio" value="'+precio+'" size="5"</td> '+
'<td><input class="btn btn-primary" onclick=editar2() id="boton" Value="aceptar" type="submit"></input></td>'+
'<td><input class="btn btn-danger" onclick=editar2() value="eliminar" type="submit"></input> ' ;
nodoTr.innerHTML = nuevoCodigoHtml;
Ajax:
function editar2(){
var especiee = jQuery("#especie").val();
var generoo = jQuery("#genero").val();
var familiaa = jQuery("#familia").val();
var calidadd = jQuery("#calidad").val();
var tamañoo = jQuery("#tamaño").val();
var ciudadd = jQuery("#ciudad").val();
var comentarioo = jQuery("#comentario").val();
var precioo = jQuery("#precio").val();
console.log("presionaste boton editar");
console.log(calidad);
$.ajax({
data: "especiee=" + especiee + "&generoo=" +generoo + "&familiaa="+familiaa+ "&calidadd="+calidadd+"&tamañoo="+tamañoo+"&ciudadd="+ciudadd+
"&comentarioo="+comentarioo+"&precioo="+precioo+"&especie=" + especie + "&genero=" +genero + "&familia="+familia+ "&calidad="+calidad+"&tamaño="+tamaño+"&ciudad="+ciudad+
"&comentario="+comentario+"&precio="+precio,
//envio los datos al ajax.php donde procesara la consulta
url: 'ajax/ajax.php',
dataType: 'html',
type: 'post',
beforeSend: function () {
//mostramos gif "cargando"
//antes de enviar la petición al fichero PHP, mostramos mensaje
jQuery("#resultado").html("Buscando");
},
success: function (response) {
console.log(response);
jQuery("#terrestres").html(response);
},
error: function(jqXHR,estado,error){
}
});
}