PHP - Problemas con la edicion de un registro plantilla AdminLTE 3

 
Vista:

Problemas con la edicion de un registro plantilla AdminLTE 3

Publicado por ignacio (1 intervención) el 26/06/2020 07:55:31
Estoy realizando una aplicación en la cual agrego el cliente satisfactoriamente y también al darle el botón editar traigo los datos de la base de datos pero al momento de querer editar el cliente, modificando algún dato del cliente me dice que a sido cambiado exitosa mente pero no cambia ningún registro, pero dice que a sido cambiado lo cual no ocurre, espero puedan ayudarme a encontrar el error. les adjunto capturas del códigos.

PD: En el sistema también tengo agregado a registro, editar y eliminar usuario, lo cual el editar utilice su estructura y el de usuario funciona perfectamente, pero en clientes tengo el problema.

De antemano Muchas gracias!

clientes.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">Clientes</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Inicio</a></li>
              <li class="breadcrumb-item active">Clientes</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
 
    <!-- Main content -->
    <section class="content">
     <div class="box">
        <div class="box-header with-border">
          <button class="btn btn-primary" data-toggle="modal" data-target="#modalAgregarCliente">Agregar Clientes</button>
        </div>
      </div>
 
      <br>
     <table class="table table-striped tabladatatable dt-responsive">
      <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">Nombre</th>
          <th scope="col">Rut</th>
          <th scope="col">Dirección</th>
          <th scope="col">Correo</th>
          <th scope="col">Teléfono</th>
          <th scope="col">Acciones</th>
          </tr>
      </thead>
      <tbody>
        <?php
          $item=null;
          $valor = null;
          $clientes = ControladorClientes::ctrMostrarClientes($item, $valor);
 
          foreach ($clientes as $key => $value) {
            echo'<tr>
          <th scope="row">'.$value['id_clientes'].'</th>
          <td>'.$value['nombre'].'</td>
          <td>'.$value['rut'].'</td>
          <td>'.$value['direccion'].'</td>
          <td>'.$value['correo'].'</td>
          <td>'.$value['telefono'].'</td>
          <td>
            <div class="btn-group">
              <button class="btn btn-warning btnEditarCliente" idCliente="'.$value["id_clientes"].'" data-toggle="modal" data-target="#modalEditarCliente"><i class="fas fa-pencil-alt"></i></button>
              <button class="btn btn-danger  btnEliminarCliente" idCliente="'.$value["id_clientes"].'" data-toggle="modal" data-target="#modalEliminarCliente"><i class="fa fa-times"></i></button>
            </div>
          </td>
        </tr>';
          }
        ?>
 
      </tbody>
</table>
 
 
<!-- Modal Nuevo Cliente -->
<div class="modal fade" id="modalAgregarCliente" role="dialog">
  <div class="modal-dialog">
     <form role="form" method="post" enctype="multipart/form-data">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Ingresar cliente</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
 
      <div class="modal-body">
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-user"></i></span>
            <input type="text" name="nuevoNombre" class="form-control input-lg" placeholder="Ingresar nombre " required>
            <!-- <input type="hidden" name="idCliente" id="idCliente" required> -->
          </div>
        </div>
 
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-address-book"></i></span>
            <input type="text" name="nuevoRut" id="nuevoRut" class="form-control input-lg" placeholder="Ingresar rut" required>
          </div>
        </div>
 
       <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-map-marker"></i></span>
            <input type="text" name="nuevoDireccion" id="nuevoDireccion" class="form-control input-lg" placeholder="Ingresar dirección" required>
          </div>
 
        </div>
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-envelope"></i></span>
            <input type="email" name="nuevoCorreo" id="nuevoCorreo" class="form-control input-lg" placeholder="Ingresar correo" required>
          </div>
 
        </div>
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-key"></i></span>
            <input type="text" name="nuevoTelefono" id="nuevoTelefono" class="form-control input-lg" placeholder="Ingresar teléfono" required>
          </div>
        </div>
 
 
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Salir</button>
        <button type="submit" class="btn btn-primary">Guardar</button>
      </div>
    </div>
    <?php
    $crearcliente = new ControladorClientes();
    $crearcliente -> ctrCrearCliente();
  ?>
</form>
  </div>
</div>
 
 <!-- Modal Editar  Usuario -->
<div class="modal fade" id="modalEditarCliente" role="dialog">
  <div class="modal-dialog">
     <form role="form" method="post" enctype="multipart/form-data">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Editar cliente</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-user"></i></span>
            <input type="text" name="editarNombre" id="editarNombre" class="form-control input-lg" required>
          </div>
        </div>
 
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-key"></i></span>
            <input type="text" name="editarRut" id="editarRut" class="form-control input-lg" placeholder="Ingresar usuario" required>
          </div>
        </div>
 
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-lock"></i></span>
            <input type="text" name="editarDireccion" id="editarDireccion" class="form-control input-lg" placeholder="Escriba la nueva contraseña" required>
 
          </div>
 
        </div>
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-user"></i></span>
            <input type="email" name="editarCorreo" id="editarCorreo" class="form-control input-lg" placeholder="Escriba la nueva contraseña">
          </div>
        </div>
 
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon" style="margin:10px 10px 0px 0px;"><i class="fa fa-user"></i></span>
            <input type="text" name="editarTelefono" id="editarTelefono" class="form-control input-lg" placeholder="Escriba la nueva contraseña">
          </div>
        </div
 
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Salir</button>
        <button type="submit" class="btn btn-primary">Guardar</button>
      </div>
    </div>
 
    <?php
 
    $editarUsuario = new ControladorClientes();
    $editarUsuario -> ctrEditarCliente();
 
    ?>
</form>
  </div>
 
 
</div>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <!-- /.content-wrapper -->
 
  <?php
  $borrarCliente = new ControladorClientes();
  $borrarCliente -> ctrBorrarCliente();
  ?>

cliente.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*=============================================
    EDITAR CLIENTE
    =============================================*/
 
    $(".btnEditarCliente").click(function(){
      var idCliente = $(this).attr("idCliente");
 
 
      var datos = new FormData();
      datos.append("idCliente", idCliente);
 
      $.ajax({
          url:"ajax/clientes.ajax.php",
          method: "POST",
          data: datos,
          cache: false,
          contentType: false,
          processData: false,
          dataType: "json",
          success: function(respuesta){
          console.log("Datos AJAX: ",respuesta);
           $("#editarNombre").val(respuesta['nombre']);
           $("#idCliente").val(respuesta['id_clientes']);
           $("#editarRut").val(respuesta['rut']);
           $("#editarDireccion").val(respuesta['direccion']);
           $("#editarCorreo").val(respuesta['correo']);
           $("#editarTelefono").val(respuesta['telefono']);
 
            },
          error : function(respuesta) {
              console.log("Error",respuesta);
         }
        });
 
 
      })
 
 
 
 
/*=============================================
Eliminar Cliente
=============================================*/
 
$(".btnEliminarCliente").click(function(){
 
var idCliente = $(this).attr("idCliente");
 
 
  Swal.fire({
  title: '¡Estas seguro que deseas eliminar el Cliente?',
  text: "Si no es asi puedes presionar el boton cancelar",
  icon: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Si, Borrar cliente'
  }).then((result) => {
    if (result.value) {
       window.location = "index.php?ruta=clientes&idCliente="+idCliente;
 
  }
})
})

cliente.modelo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
	require_once "conexion.php";
	class ModeloClientes{
 
		static public function mdlEditarCliente($tabla,$datos){
			$stmt = conexion::conectar()->prepare("UPDATE $tabla SET nombre=:nombre, rut=:rut, direccion=:direccion, correo=:correo, telefono=:telefono WHERE id_clientes=:id_clientes");
 
			$stmt -> bindParam(":nombre",$datos['nombre'],PDO::PARAM_STR);
			$stmt -> bindParam(":id_clientes",$datos['id_clientes'],PDO::PARAM_INT);
			$stmt -> bindParam(":rut",$datos['rut'],PDO::PARAM_STR);
			$stmt -> bindParam(":direccion",$datos['direccion'],PDO::PARAM_STR);
			$stmt -> bindParam(":correo",$datos['correo'],PDO::PARAM_STR);
			$stmt -> bindParam(":telefono",$datos['telefono'],PDO::PARAM_STR);
 
			if($stmt->execute()){
 
				return "ok";
 
			}else{
 
				return "error";
			}
 
			$stmt ->close();
			$stmt = null;
		}
 
 
		static public function mdlMostrarClientes($tabla,$item,$valor){
 
			if($item!=null){
				$stmt = conexion::conectar()->prepare("SELECT * FROM $tabla WHERE $item = :$item");
				$stmt -> bindParam(":".$item,$valor,PDO::PARAM_STR);
				$stmt -> execute();
				return $stmt->fetch();
			}else{
				$stmt = conexion::conectar()->prepare("SELECT * FROM $tabla");
				$stmt -> execute();
				return $stmt->fetchAll();
			}
 
			$stmt ->close();
			$stmt=null;
 
		}
 
		static public function mdlIngresarCliente($tabla,$datos){
 
			$stmt = conexion::conectar()->prepare("INSERT INTO $tabla (nombre,rut,direccion,correo,telefono) VALUES (:nombre,:rut,:direccion,:correo,:telefono)");
			$stmt -> bindParam(":nombre",$datos['nombre'],PDO::PARAM_STR);
			$stmt -> bindParam(":rut",$datos['rut'],PDO::PARAM_STR);
			$stmt -> bindParam(":direccion",$datos['direccion'],PDO::PARAM_STR);
			$stmt -> bindParam(":correo",$datos['correo'],PDO::PARAM_STR);
			$stmt -> bindParam(":telefono",$datos['telefono'],PDO::PARAM_STR);
 
			if($stmt->execute()){
				return "ok";
			}else{
				return "error";
			}
			$stmt ->close();
			$stmt = null;
		}
 
		static public function mdlActualizarCliente($tabla,$item1,$valor1,$item2,$valor2){
			$stmt = conexion::conectar()->prepare("UPDATE $tabla SET $item1 = :$item1 WHERE $item2 = :$item2");
			$stmt -> bindParam(":".$item1,$valor1,PDO::PARAM_STR);
			$stmt -> bindParam(":".$item2,$valor2,PDO::PARAM_STR);
			if($stmt->execute()){
				return "ok";
			}else{
				return "error";
			}
			$stmt ->close();
			$stmt = null;
 
		}
 
		static public function mdlBorrarCliente($tabla,$datos){
			$stmt = conexion::conectar()->prepare("DELETE FROM $tabla WHERE id_clientes = :id_clientes");
			$stmt -> bindParam(":id_clientes",$datos,PDO::PARAM_STR);
			if($stmt->execute()){
				return "ok";
			}else{
				return "error";
			}
			$stmt -> close();
			$stmt = null;
 
		}
	}

clientes.controlador.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
 
	class ControladorClientes{
 
		static public function ctrEditarCliente(){
 
			if(isset($_POST['editarNombre'])){
 
				if(preg_match('/^[a-zA-Z0-9ñÑaáéÉíÍóÓúÚ ]+$/',$_POST['editarNombre']) &&
					preg_match('/^[.\-\-a-zA-Z0-9]+$/',$_POST['editarRut']) &&
					preg_match('/^[#\.\-a-zA-Z0-9 ]+$/', $_POST["editarDireccion"]) &&
					preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $_POST["editarCorreo"]) &&
					preg_match('/^[+\-\.\-a-zA-Z0-9ñÑaáéÉíÍóÓúÚ ]+$/',$_POST['editarTelefono'])){
 
					$tabla = "clientes";
 
					$datos = array( "nombre"=>$_POST['editarNombre'],
									"id_clientes"=>$_POST['idCliente'],
									"rut"=>$_POST['editarRut'],
									"direccion"=>$_POST['editarDireccion'],
									"correo"=>$_POST['editarCorreo'],
									"telefono"=>$_POST['editarTelefono']);
 
					$respuesta  = ModeloClientes::mdlEditarCliente($tabla, $datos);
 
					if($respuesta=="ok"){
						echo"<script>
							Swal.fire({
								title: 'Success!',
								text: '¡El cliente ha sido actualizaddo correctamente!',
								icon: 'success',
								confirmButtonText:'Ok'
								}).then((result)=>{
									if(result.value){
										window.location = 'clientes';
									}
								})
						</script>";
					}
				}else{
					echo"<script>
							Swal.fire({
								title: 'Error!',
								text: '¡No puedes usar caraceres especiales en el campo nombre!',
								icon: 'error',
								confirmButtonText:'Ok'
								})
						</script>";
				}
				}
		}
 
		static public function ctrCrearCliente(){
			if(isset($_POST['nuevoNombre'])){
 
				if(preg_match('/^[a-zA-Z0-9ñÑaáéÉíÍóÓúÚ ]+$/',$_POST['nuevoNombre']) &&
					preg_match('/^[.\-\-a-zA-Z0-9]+$/',$_POST['nuevoRut']) &&
					preg_match('/^[#\.\-a-zA-Z0-9 ]+$/', $_POST["nuevoDireccion"]) &&
					preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $_POST["nuevoCorreo"]) &&
					preg_match('/^[+\-\.\-a-zA-Z0-9ñÑaáéÉíÍóÓúÚ ]+$/',$_POST['nuevoTelefono'])){
 
 
					$tabla = "clientes";
					$datos = array("nombre"=>$_POST['nuevoNombre'],
									"rut"=>$_POST['nuevoRut'],
									"direccion"=>$_POST['nuevoDireccion'],
									"correo"=>$_POST['nuevoCorreo'],
									"telefono"=>$_POST['nuevoTelefono']);
 
					$respuesta  = ModeloClientes::mdlIngresarCliente($tabla, $datos);
					if($respuesta=="ok"){
						echo"<script>
							Swal.fire({
								title: 'Ingresado!',
								text: '¡Registro Exitoso!',
								icon: 'success',
								confirmButtonText:'Ok'
								}).then((result)=>{
									if(result.value){
										window.location = 'clientes';
									}
								});
						</script>";
					}
				}else{
					echo"<script>
							Swal.fire({
								title: 'Error!',
								text: '¡No puedes usar caraceres especiales en el campo!',
								icon: 'error',
								confirmButtonText:'Ok'
								});
						</script>";
				}
			}
		}
 
		static public function ctrMostrarClientes($item,$valor){
			$tabla="clientes";
			$respuesta = ModeloClientes::mdlMostrarClientes($tabla,$item,$valor);
			return $respuesta;
		}
 
 
		static public function ctrBorrarCliente(){
			if(isset($_GET['idCliente'])){
				$tabla = "clientes";
				$datos = $_GET['idCliente'];
 
					$respuesta = ModeloClientes::mdlBorrarCliente($tabla,$datos);
					if($respuesta=="ok"){
						echo"<script>
							Swal.fire({
								title: 'Success!',
								text: '¡El cliente ha sido borrado correctamente!',
								icon: 'success',
								confirmButtonText:'Ok'
								}).then((result)=>{
									if(result.value){
										window.location = 'clientes';
									}
								})
						</script>";
					}
 
			}
		}
	}
clientes.ajax.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
 
 
 
require_once "../controladores/clientes.controlador.php";
require_once "../modelos/clientes.modelo.php";
class AjaxClientes{
 
	/*=============================================
	EDITAR clientes
	=============================================*/
 
	public $idCliente;
 
	public function ajaxEditarClientes(){
 
			$item = "id_clientes";
			$valor = $this->idCliente;
			$respuesta = ControladorClientes::ctrMostrarClientes($item, $valor);
			echo json_encode($respuesta);
			//$myArr = array("John", "Mary", "Peter", "Sally","highlight_file","pedro",$item,$valor);
			//$myJSON = json_encode($myArr);
			//echo 'Hola mundo';
			//echo $myJSON;
	}
 
 
 
 
}
 
/*=============================================
EDITAR clientes
=============================================*/
if(isset($_POST["idCliente"])){
	$editar = new AjaxClientes();
	$editar -> idCliente = $_POST["idCliente"];
	$editar -> ajaxEditarClientes();
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder