PHP - PDO insert no guarda y no da error
Publicado por Luis (3 intervenciones) el 10/12/2019 03:03:22
Buenas, el siguiente código no guarda pero tampoco da ningún error, favor si alguien puede ayudarme.
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
<?php
require "include/conexionPDO.php";
if(isset($_POST['submit'])){
$nuevo_usuario = array(
"USUARIO" => $_POST['USUARIO'],
"CLAVE" => $_POST['CLAVE'],
"NOMBRE" => $_POST['NOMBRE'],
"APELLIDOP" => $_POST['APELLIDOP'],
"APELLIDOM" => $_POST['APELLIDOM'],
"RUT" => $_POST['RUT'],
"CARGO" => $_POST['CARGO'],
"PERFIL" => $_POST['PERFIL'],
"ESTADO" => $_POST['ESTADO']
);
$sql="insert into usuarios (USUARIO, CLAVE, NOMBRE_USUARIO, APELLIDOP_USUARIO, APELLIDOM_USUARIO, RUT_USUARIO, CARGO, ID_PERFIL, ESTADO) values(:USUARIO, :CLAVE, :NOMBRE, :APELLIDOP, :APELLIDOM, :RUT, :CARGO, :PERFIL, :ESTADO)";
try {
$statement = $conexionPDO->prepare($sql);
$statement->execute($nuevo_usuario);
} catch(PDOException $error){
echo $error->getMessage();
}
}
?>
<?php include "templates/header.php";?>
<!-- Content page-->
<section class="full-box dashboard-contentPage">
<!-- NavBar -->
<nav class="full-box dashboard-Navbar">
<ul class="full-box list-unstyled text-right">
<li class="pull-left">
<a href="#!" class="btn-menu-dashboard"><i class="zmdi zmdi-more-vert"></i></a>
</li>
</ul>
</nav>
<!-- Content page -->
<div class="container-fluid">
<div class="page-header">
<h1 class="text-titles"><i class="zmdi zmdi-account zmdi-hc-fw"></i> Agregar <small>Usuario</small></h1>
</div>
<p class="lead">Registrar solo usuarios autorizador por jefatura</p>
<?php if (isset($_POST['submit']) && $statement) : ?>
<blockquote class="lead"><?php echo $_POST['USUARIO']; ?> se ha añadido correctamente. </blockquote>
<?php endif; ?>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<ul class="nav nav-tabs" style="margin-bottom: 15px;">
<li class="active"><a href="#new" data-toggle="tab">Nuevo</a></li>
<li><a href="#list" data-toggle="tab">Lista</a></li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="new">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-md-10 col-md-offset-1">
<form method="post">
<div class="form-group label-floating">
<label class="control-label">Usuario</label>
<input name="USUARIO" id="USUARIO" class="form-control" type="text">
</div>
<div class="form-group label-floating">
<label class="control-label" >Password</label>
<input name="CLAVE" id="CLAVE" class="form-control" type="password">
</div>
<div class="form-group label-floating">
<label class="control-label">nombre</label>
<input name="NOMBRE" id="NOMBRE" class="form-control" type="text">
</div>
<div class="form-group label-floating">
<label class="control-label" >Apellido Paterno</label>
<input name="APELLIDOP" id="APELLIDOP" class="form-control" type="text">
</div>
<div class="form-group label-floating">
<label class="control-label">Apellido Materno</label>
<input name="APELLIDOM" id="APELLIDOM" class="form-control" type="text">
</div>
<div class="form-group label-floating">
<label class="control-label">Rut</label>
<input name="RUT" id="RUT" class="form-control" type="text">
</div>
<div class="form-group label-floating">
<label class="control-label">Cargo</label>
<input name="CARGO" id="CARGO" class="form-control" type="text">
</div>
<div class="form-group label-floating">
<label class="control-label">Perfil</label>
<select name="PERFIL" id="PERFIL" class="form-control">
<?php
include "include/conexion.php";
$query = mysqli_query($conexion,"select ID_PERFIL , PERFIL_USUARIO from perfiles");
while($datos = mysqli_fetch_array($query)){ ?>
<option class="control-option" value=""></option>
<option value="<?php echo $datos['ID_PERFIL']?>"><?php echo $datos['PERFIL_USUARIO']?></option>
<?php } ?>
</select>
<fieldset>
<div class="form-group label-floating">
<label class="control-label">Usuario Activo</label>
<input class="radio-inline" type="radio" name="ESTADO" id="ESTADO" value="Activo" checked>
</div>
<div class="form-group label-floating">
<label class="control-label">Usuario Inactivo</label>
<input class="radio-inline" type="radio" name="ESTADO" id="ESTADO" value="Inactivo">
</div>
</fieldset>
</div>
<p class="text-center">
<input name="submit" class="btn btn-info btn-raised btn-sm" type="submit" value="Grabar">
</p>
</form>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="list">
<div class="table-responsive">
<table class="table table-hover text-center">
<thead>
<tr>
<th class="text-center">Usuario</th>
<th class="text-center">Nombre</th>
<th class="text-center">Apell P</th>
<th class="text-center">Apell M</th>
<th class="text-center">Rut</th>
<th class="text-center">Cargo</th>
<th class="text-center">Perfil</th>
<th class="text-center">Estado</th>
<th class="text-center">Update</th>
<th class="text-center">Delete</th>
</tr>
</thead>
<tbody>
<?php $sql="select * from usuarios inner join perfiles";
$result=mysqli_query($conexion,$sql);
while($mostrar=mysqli_fetch_array($result)){
?>
<tr>
<td><?php echo $mostrar['USUARIO']; ?></td>
<td><?php echo $mostrar['NOMBRE_USUARIO']; ?></td>
<td><?php echo $mostrar['APELLIDOP_USUARIO']; ?></td>
<td><?php echo $mostrar['APELLIDOM_USUARIO']; ?></td>
<td><?php echo $mostrar['RUT_USUARIO']; ?></td>
<td><?php echo $mostrar['CARGO']; ?></td>
<td><?php echo $mostrar['PERFIL_USUARIO']; ?></td>
<td><?php echo $mostrar['ESTADO']; ?></td>
<td><a href="include/update.php" class="btn btn-success btn-raised btn-xs"><i class="zmdi zmdi-refresh"></i></a></td>
<td><a href="#!" class="btn btn-danger btn-raised btn-xs"><i class="zmdi zmdi-delete"></i></a></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<?php include "templates/footer.php";?>
Valora esta pregunta


0