PHP - No me inserta los datos a la base de datos

 
Vista:
sin imagen de perfil
Val: 16
Ha aumentado su posición en 10 puestos en PHP (en relación al último mes)
Gráfica de PHP

No me inserta los datos a la base de datos

Publicado por Javiera (6 intervenciones) el 12/05/2021 22:57:08
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
<?php
//Se inicia sesión
session_start();
?>
 
<!DOCTYPE html>
<html>
 
<head>
 
  <meta charset="utf-8">
  <title>Formulario SERTEC</title>
  <meta name="description" content="PHP">
  <link rel="stylesheet"  href="css/style.css">
 
</head>
 
<body>
 
<header style="margin-top: 120px;" >
  <section class="wrapper">
    <nav >
        <ul>
          <li><a href="#Info">Información del Cliente</a></li>
          <li><a href="#Pre">Información del Audífonos</a></li>
          <li><a href="#Peri">Accesorio Audífonos</a></li>
          <li><a href="#Post">Información</a></li>
          <li><a href="#Post">Fechas y Finalizar</a></li>
          <li><a href="#boton">Ir a Revisar</a></li>
        </ul>
    </nav>
  </section>
</header>
<div style="display:block;" >
<img src="img/Logo.png" style="width: 300px;height: auto;margin-top: 10px;margin-left: 5%;" >
<form action='logOut.php' method='post' >
    <input style="padding: 10px; float: right; margin-right: 50px; margin-top: 51px;" type="submit" value="Salir" ><br><br>
</form>
<form action='menu.php' method='post' >
    <input style="padding: 10px; float: right; margin-right: 10px; margin-top: 15px;" type="submit" value="Menu" ><br><br>
</form>
<?php echo '<h3 style="float: right; margin-right: 25px; color:#e6b800;">Bienvenido(a) '.$_SESSION["usuarios"].'</h3>'; ?>
</div>
<br><br>
 
 
 
<h1 id="titulo">Formulario Audífonos <br> SERTEC</h1>
<form action='conexion.php' method='post' id="Form1" >
  <fieldset>
   <legend id="Info"><h2>Información del Cliente</h2></legend>
    <br>
    <label>Sucursal</label>
    <label title="Por favor digite sólo letras">*<label>
    <input type="text"  name="Sucursal" id="Sucursal" placeholder="Sucursal" required>
    <label>Cliente</label>
    <label title="Por favor digite sólo letras">*<label>
    <input type="text" name="Nombre" id="Nombre" placeholder="Nombre" required>
    <label>RUT</label>
    <label title="Por favor digite sólo números. 9 dígitos">*<label>
    <input type="text"  name="cedula" id="cedula" maxlength="9" placeholder="Cédula" required>
    <label>Fono</label>
    <label title="Por favor digite sólo números. 9 dígitos">*<label>
    <input type="text" name="Fono" id="Fono" placeholder="Fono" maxlength="9" required>
        <br><br>
    <label>Dirección</label>
    <input type="text" name="Direccion" id="Direccion" placeholder="Dirección" required>
    <label>Comuna</label>
    <label title="Por favor digite sólo letras">*<label>
    <input type="text" name="Comuna" id="Comuna" placeholder="Comuna" required>
        <label>Región</label>
    <select name="Region" required>
        <option>Seleccione una opción</option>
        <option>Región de Arica y Parinacota</option>
        <option>Región de Tarapacá</option>
        <option>Región de Antofagasta</option>
        <option>Región de Atacama</option>
        <option>Región de Coquimbo</option>
        <option>Región de Valparaíso</option>
        <option>Región del Libertador Gral. Bernardo O’Higgins</option>
        <option>Región del Maule</option>
        <option>Región del Biobío</option>
        <option>Región de La Araucanía</option>
        <option>Región de Los Ríos</option>
        <option>Región de Los Lagos</option>
        <option>Región de Aysén del Gral. Carlos Ibáñez del Campo</option>
        <option>Región de Magallanes y de la Antártica Chilena</option>
        <option>Región Metropolitana de Santiago</option>
    </select>
    <br><br>
  </fieldset>
  <br>
 
  <fieldset>
    <legend id="Pre"><h2>Información del Audífono</h2></legend>
    <br>
    <label>Fecha de Compra/Entrega</label>
    <input type="date" name="FechaCompra" id="FechaCompra" data-date-format="DD MMMM YYYY" required>
    <br><br>
    <label>Articulo</label>
    <label title="Por favor escriba el Articulo">*<label>
      <br>
    <input type="text"  name="Articulo" id="Articulo" placeholder="Especifique" size="120" required>
    <br><br>
    <label>Marca</label>
    <label title="Por favor Seleccione la Marca">*<label>
 
    Bernafon <input type="checkbox" name="Marca" value="Bernafon">
    Resound  <input type="checkbox" name="Marca" value="Resound">
    <br><br>
    <label>Modelo</label>
    <br>
    <input type="text"  name="Modelo" id="Modelo" placeholder="Especifique" size="120" required>
    <br><br>
 
    <label>N° de Serie *</label>
    <br>
    <input type="text"  name="NSerie" id="NSerie" placeholder="Especifique" size="120" required>
    <br><br>
 
  </fieldset>
  <br>
  <fieldset>
      <legend id="Post"><h2>Accesorio Audífonos</h2></legend>
      <br>
<label>Accesorio: </label>
    Cargador  <input type="checkbox" name="Accesorio" value="Cargador">
    Molde  <input type="checkbox" name="Accesorio" value="Molde">
    <br>
    <label>Otros</label>
    <input type="text" name="Accesorio" size="120">
    <br><br>
<label>Garantia: </label>
    Si  <input type="checkbox" name="Garantia" value="Si">
    No  <input type="checkbox" name="Garantia" value="No">
</fieldset>
 
  <br>
 
  <fieldset>
    <legend id="Post"><h2>Información</h2></legend>
    <br>
    <label>Motivo de Ingreso y Observaciones de Recepción:</label>
    <input type="text"  name="MotivoIngreso" id="MotivoIngreso" placeholder="Especifique" size="120" required>
    <br><br>
    <label>Informe de Reparación:</label required>
      <br>
    <input type="text"  name="InformeReparacion" id="InformeReparacion" placeholder="Especifique" size="120" required>
    <br><br>
    <label>Repuestos Usados en Reparación</label required>
    <input type="text"  name="RepuestosUsados" id="RepuestosUsados" placeholder="Especifique" size="120" required>
    <br><br>
  </fieldset>
  <br>
 
  <fieldset>
    <legend id="Desa"><h2>Fechas y Finalización</h2></legend>
    <br>
      <fieldset class="fieldsetInterno">
 
    <legend id="Desa"><h2>Fechas</h2></legend>
    <label>Fecha Recepción</label>
    <input type="date" name="FechaRecepcion" id="FechaRecepcion" data-date-format="DD MMMM YYYY" required>
    <br><br>
 
    <label>Fecha de Propuesta</label>
    <input type="date" name="FechaPropuesta" id="FechaPropuesta" data-date-format="DD MMMM YYYY" required>
    <br><br>
 
    <label>Fecha de Entrega</label>
    <input type="date" name="FechaEntrega" id="FechaEntrega" data-date-format="DD MMMM YYYY" required>
    <br><br>
      </fieldset>
 
      <br>
 
      <fieldset class="fieldsetInterno">
      <br>
      <legend><h3>Entrega del Audífono</h3></legend>
 
        <ul>
        <li>
        <label>Repuesto</label>
        <br>
        <input align="left" type="text"  name="Repuestos" id="Repuestos" placeholder="Especifique" size="120" required>
        <br><br>
        </li>
        <li>
        <label>Total</label>
        <br>
        <input align="center" type="text"  name="Total" id="Total" placeholder="Especifique" size="120" required>
        <br><br>
        </ul>
        <legend>Archivos Adjuntados</legend>
        <br>
        <input type="file">
        </fieldset>
        <br><br>
 
 
  </fieldset>
      <br>
      <br>
 
  <input style="position: absolute; left: 50%;" type="submit" value="Revisar" id="boton"><br><br>
 
  </form>
 
</body>
 
</html>

[-- conexion.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
<?php
	$Sucursal = $_POST['Sucursal'];
    $Cliente = $_POST['Nombre'];
    $RUT = $_POST['cedula'];
    $Fono = $_POST['Fono'];
    $Direccion = $_POST['Direccion'];
    $Comuna = $_POST['Comuna'];
    $Region = $_POST['Region'];
    $FechaCompra = $_POST['FechaCompra'];
    $Articulo = $_POST['Articulo'];
    $Marca = $_POST['Marca'];
    $Modelo = $_POST['Modelo'];
    $NSerie = $_POST['NSerie'];
    $Accesorio = $_POST['Acessorio'];
    $Garantia = $_POST['Garantia'];
    $MotivoIngreso = $_POST['MotivoIngreso'];
    $InformeReparacion = $_POST['InformeReparacion'];
    $RepuestosUsados = $_POST['RepuestosUsados'];
    $FechaRecepcion = $_POST['FechaRecepcion'];
    $FechaPropuesta = $_POST['FechaPropuesta'];
    $FechaEntrega = $_POST['FechaEntrega'];
    $Repuestos = $_POST['Repuestos'];
    $Total = $_POST['Total'];
 
 
    if (!empty($Sucursal) || !empty($Nombre)|| !empty($cedula)|| !empty($Fono)|| !empty($Direccion)||
    !empty($Comuna)|| !empty($Region)|| !empty($FechaCompra)|| !empty($Articulo)|| !empty($Marca)||
    !empty($Modelo)|| !empty($NSerie)|| !empty($Acessorio)|| !empty($Garantia)|| !empty($MotivoIngreso)||
    !empty($InformeReparacion)|| !empty($RepuestosUsados)|| !empty($FechaRecepcion)||
    !empty($FechaPropuesta)|| !empty($FechaEntrega)|| !empty($Repuestos)|| !empty($Total) ){
 
	$host="localhost";
	$dbuser="root";
	$dbpass="";
	$dbname="javiera";
 
	$conn= new mysqli_connect($host,$dbuser,$dbpass,$dbname);
	if (mysqli_connect_error()) {
		die('Connect Error('.mysqli_connect_errorno().')'.mysqli_connect_error());
	}
	else
		"SELECT Fono from formulario_sertec where Fono = ? limit 1";
		"INSERT INTO formulario_sertec (Sucursal, Cliente, cedula, Fono, Direccion, Comuna, Region,
         FechaCompra, Articulo, Marca, Modelo, NSerie, Acessorio, Garantia, MotivoIngreso,
         InformeReparacion, RepuestosUsados, FechaRecepcion, FechaPropuesta, FechaEntrega, Repuestos,
         Total) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
 
		$stmt = $conn -> prepare($SELECT);
		$stmt ->bind_param("i",$Fono);
		$stmt ->execute();
		$stmt ->bind_result($Fono);
		$stmt ->store_result();
		$rnum= $stmt->num_rows;
		if ($rnum == 0) {
			$stmt ->close();
			$stmt = $conn->prepare($INSERT);
			$stmt ->bind_param("sssissssssssssssssssss",$Sucursal,$Cliente,$RUT, $Fono, $Direccion,
            $Comuna, $Region, $FechaCompra, $Articulo, $Marca, $Modelo, $NSerie, $Accesorio, $Garantia,
            $MotivoIngreso, $InformeReparacion, $RepuestosUsados, $FechaRecepcion, $FechaPropuesta,
            $FechaEntrega, $Repuestos, $Total);
			$stmt->execute();
			echo "Registro Completado";
		}
		else{
			echo "alguien ya registro ese número";
		}
		$stmt->close();
		$conn->close();
 
	}
 
 
else{
	echo "Todos los datos son Obligatorios.";
	die();
}
?>
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
sin imagen de perfil
Val: 16
Ha aumentado su posición en 10 puestos en PHP (en relación al último mes)
Gráfica de PHP

No me inserta los datos a la base de datos

Publicado por Javiera (6 intervenciones) el 13/05/2021 05:08:22
Este es el error, pero me dijieron que pusiera if (isset($_POST['form1'])), pero al momento de hacer eso, me dice que se registraron pero no hay nada

Warning: Undefined array key "Sucursal" in C:\xampp2\htdocs\formulario\conexion.php on line 3

Warning: Undefined array key "Nombre" in C:\xampp2\htdocs\formulario\conexion.php on line 4

Warning: Undefined array key "cedula" in C:\xampp2\htdocs\formulario\conexion.php on line 5

Warning: Undefined array key "Fono" in C:\xampp2\htdocs\formulario\conexion.php on line 6

Warning: Undefined array key "Direccion" in C:\xampp2\htdocs\formulario\conexion.php on line 7

Warning: Undefined array key "Comuna" in C:\xampp2\htdocs\formulario\conexion.php on line 8

Warning: Undefined array key "Region" in C:\xampp2\htdocs\formulario\conexion.php on line 9

Warning: Undefined array key "FechaCompra" in C:\xampp2\htdocs\formulario\conexion.php on line 10

Warning: Undefined array key "Articulo" in C:\xampp2\htdocs\formulario\conexion.php on line 11

Warning: Undefined array key "Marca" in C:\xampp2\htdocs\formulario\conexion.php on line 12

Warning: Undefined array key "Modelo" in C:\xampp2\htdocs\formulario\conexion.php on line 13

Warning: Undefined array key "NSerie" in C:\xampp2\htdocs\formulario\conexion.php on line 14

Warning: Undefined array key "Acessorio" in C:\xampp2\htdocs\formulario\conexion.php on line 15

Warning: Undefined array key "Garantia" in C:\xampp2\htdocs\formulario\conexion.php on line 16

Warning: Undefined array key "MotivoIngreso" in C:\xampp2\htdocs\formulario\conexion.php on line 17

Warning: Undefined array key "InformeReparacion" in C:\xampp2\htdocs\formulario\conexion.php on line 18

Warning: Undefined array key "RepuestosUsados" in C:\xampp2\htdocs\formulario\conexion.php on line 19

Warning: Undefined array key "FechaRecepcion" in C:\xampp2\htdocs\formulario\conexion.php on line 20

Warning: Undefined array key "FechaPropuesta" in C:\xampp2\htdocs\formulario\conexion.php on line 21

Warning: Undefined array key "FechaEntrega" in C:\xampp2\htdocs\formulario\conexion.php on line 22

Warning: Undefined array key "Repuestos" in C:\xampp2\htdocs\formulario\conexion.php on line 23

Warning: Undefined array key "Total" in C:\xampp2\htdocs\formulario\conexion.php on line 24
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

No me inserta los datos a la base de datos

Publicado por joel (1269 intervenciones) el 13/05/2021 08:21:21
Hola Javiera, no son bien, bien errores, son Warning...
Lo que te esta indicando, es que no existe el indice "Sucursal" en el array $_POST

Eso es porque no se ha enviado el formulario o ese campo.

Una manera de solucionarlo, es con la función isset()... algo así:
1
2
3
if (isset($_POST['Sucursal'])) {
    $Sucursal = $_POST['Sucursal'];
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 16
Ha aumentado su posición en 10 puestos en PHP (en relación al último mes)
Gráfica de PHP

No me inserta los datos a la base de datos

Publicado por Javiera (6 intervenciones) el 13/05/2021 08:55:48
Ahora me arroja ese error
Fatal error: Uncaught Error: Call to a member function bind_param() on bool in C:\xampp2\htdocs\Sertec\Sertec\Formulario\conexion.php:93 Stack trace: #0 {main} thrown in C:\xampp2\htdocs\Sertec\Sertec\Formulario\conexion.php on line 93

No me habia fijado que no puse el nombre de la variable

1
2
$SELECT = "SELECT Fono from formulario_sertec where Fono = ? limit 1";
	$INSERT = "INSERT INTO formulario_sertec (Sucursal, Cliente, cedula, Fono, Direccion, Comuna, Region, FechaCompra, Articulo, Marca, Modelo, NSerie, Acessorio, Garantia, MotivoIngreso, InformeReparacion, RepuestosUsados, FechaRecepcion, FechaPropuesta, FechaEntrega, Repuestos, Total) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 393
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

No me inserta los datos a la base de datos

Publicado por Jefferson (203 intervenciones) el 13/05/2021 15:07:25
Hola amigo

en la linea 42.
1
2
3
4
5
"SELECT Fono from formulario_sertec where Fono = ? limit 1";
	 "INSERT INTO formulario_sertec (Sucursal, Cliente, cedula, Fono, Direccion, Comuna, Region,
         FechaCompra, Articulo, Marca, Modelo, NSerie, Acessorio, Garantia, MotivoIngreso,
         InformeReparacion, RepuestosUsados, FechaRecepcion, FechaPropuesta, FechaEntrega, Repuestos,
         Total) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

eso esta flotando !

Deberia ser
1
2
3
4
5
$SELECT="SELECT Fono from formulario_sertec where Fono = ? limit 1";
	 "INSERT INTO formulario_sertec (Sucursal, Cliente, cedula, Fono, Direccion, Comuna, Region,
         FechaCompra, Articulo, Marca, Modelo, NSerie, Acessorio, Garantia, MotivoIngreso,
         InformeReparacion, RepuestosUsados, FechaRecepcion, FechaPropuesta, FechaEntrega, Repuestos,
         Total) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

prueba y comentas
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 16
Ha aumentado su posición en 10 puestos en PHP (en relación al último mes)
Gráfica de PHP

No me inserta los datos a la base de datos

Publicado por Javiera (6 intervenciones) el 13/05/2021 18:23:17
Fatal error: Uncaught Error: Call to a member function bind_param() on bool in C:\xampp2\htdocs\Sertec\Sertec\Formulario\conexion.php:93 Stack trace: #0 {main} thrown in C:\xampp2\htdocs\Sertec\Sertec\Formulario\conexion.php on line 93
Me arroja ese error que en este caso es la linea 57
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar