Guest User

Untitled

a guest
Jan 13th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2. include 'conexion.php';
  3.  
  4. $id = $_POST['id'];
  5. $texto = $_POST['texto'];
  6. $columna = $_POST['columna'];
  7.  
  8. $consulta ="UPDATE usuarios SET :columna = :texto WHERE id = :id";
  9.  
  10. $statement = $con->prepare($consulta);
  11. $statement->bindParam(':id', $id);
  12. $statement->bindParam(':texto', $texto);
  13. $statement->bindParam(':columna', $columna);
  14. $statement->execute();
  15.  
  16. if(!$statement){
  17. echo 'Error al actualizar';
  18. }else{
  19. echo 'Se han actualizado los datos';
  20. }
  21. ?>
  22.  
  23. $(document).on("blur", "#nombre", function(){
  24. var id = $(this).data("id_user");
  25. var nombre = $(this).text();
  26. actualizar_datos(id, nombre, "nombre");
  27. });
  28.  
  29. function actualizar_datos(id, texto, columna){
  30. $.ajax({
  31. url: "actualizar.php",
  32. method: "POST",
  33. data: {
  34. id: id,
  35. texto: texto,
  36. columna: columna
  37. },
  38. success: function(data){
  39. obtener_datos();
  40. alert(data);
  41. }
  42. })
  43. }
Add Comment
Please, Sign In to add comment