insertar datos en bd mysqli desde formulario php
Publicado por Erik (23 intervenciones) el 06/09/2020 23:45:32
cuando realizo insertar, enviando los datos proporcionados desde el formulario, éxito..
pero cuando imprimo antes en otra pagina los datos, para verificar los mismos y, de ser correctos por medio de un boton enviar a la pagina de insercion (primera pagina) ya no llegan las variables $_POST, como logro que a esta primera pagina se disponga de dichas variables $_POST..
imagen donde llegan primera vez $_POST para verificar datos introducidos

segunda imagen donde claramente no llegan las variables $_POST....

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
<?php
include("../conexion.php");
if(isset($_POST['nombre'],$_POST['apellido'],$_POST['edad'],$_POST['sexo'],$_POST['cargo'],$_POST['departamento'],$_POST['telefono'])){
if (empty($_POST['nombre']) || empty($_POST['apellido']) || empty($_POST['edad']) || empty($_POST['sexo']) || empty($_POST['cargo']) || empty($_POST['departamento']) || empty($_POST['telefono'])){
}else{
$nombre = $_POST["nombre"];
$apellido = $_POST["apellido"];
$edad = $_POST["edad"];
$sexo = $_POST["sexo"];
$cargo = $_POST["cargo"];
$departamento = $_POST["departamento"];
$telefono = $_POST["telefono"];
mysqli_query($mysqli,("INSERT INTO clientes (id,nombre,apellido,edad,sexo,cargo,depto,telefono)
VALUES ('0','$nombre','$apellido','$edad','$sexo','$cargo','$departamento','$telefono')"));
}
}
?>
<DOCTYPE html>
<html lang="es">
<head>
<link href='https://fonts.googleapis.com/css?family=Aclonica' rel='stylesheet'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="../estilos.css">
</head>
<body>
<header>
<h1>DATOS INSERTARTADOS EN LA BASE</h1>
</header>
<div style="background-color:navy; padding:2em">
<form action="index.php" method="post">
<button type="submit">back to form</button>
</form>
</div>
<table border="1">
<tr>
<!--td class="titulos">Id</td-->
<td class="titulos">Nombre</td>
<td class="titulos">Apellido</td>
<td class="titulos">Sexo</td>
<td class="titulos">Cargo</td>
<td class="titulos">Departamento</td>
<td class="titulos">Edad</td>
<td class="titulos">Telefono</td>
</tr>
<tr>
<!--td class="tituloss"><?php echo $row['id'] ?></td-->
<td class="tituloss"><?php echo $_POST['nombre'] ?></td>
<td class="tituloss"><?php echo $_POST['apellido'] ?></td>
<td class="tituloss"><?php echo $_POST['sexo'] ?></td>
<td class="tituloss"><?php echo $_POST['cargo'] ?></td>
<td class="tituloss"><?php echo $_POST['departamento'] ?></td>
<td class="tituloss"><?php echo $_POST['edad'] ?></td>
<td class="tituloss"><?php echo $_POST['telefono'] ?></td>
</tr>
</table>
</body>
</html>
pero cuando imprimo antes en otra pagina los datos, para verificar los mismos y, de ser correctos por medio de un boton enviar a la pagina de insercion (primera pagina) ya no llegan las variables $_POST, como logro que a esta primera pagina se disponga de dichas variables $_POST..
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
<DOCTYPE html>
<html lang="es">
<head>
<link href='https://fonts.googleapis.com/css?family=Aclonica' rel='stylesheet'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="../estilos.css">
</head>
<body>
<header>
<h1>DATOS POR INSERTAR A LA BASE</h1>
</header>
<div style="background-color:navy; padding:2em">
<form action="index.php" method="post">
<button type="submit">corregir datos erroneos</button>
</form>
<form action="insertar.php" method="post">
<button type="submit">enviar datos correctos</button>
</form>
</div>
<table border="1">
<tr>
<!--td class="titulos">Id</td-->
<td class="titulos">Nombre</td>
<td class="titulos">Apellido</td>
<td class="titulos">Sexo</td>
<td class="titulos">Cargo</td>
<td class="titulos">Departamento</td>
<td class="titulos">Edad</td>
<td class="titulos">Telefono</td>
</tr>
<tr>
<!--td class="tituloss"><?php echo $row['id'] ?></td-->
<td class="tituloss"><?php echo $_POST['nombre'] ?></td>
<td class="tituloss"><?php echo $_POST['apellido'] ?></td>
<td class="tituloss"><?php echo $_POST['sexo'] ?></td>
<td class="tituloss"><?php echo $_POST['cargo'] ?></td>
<td class="tituloss"><?php echo $_POST['departamento'] ?></td>
<td class="tituloss"><?php echo $_POST['edad'] ?></td>
<td class="tituloss"><?php echo $_POST['telefono'] ?></td>
</tr>
</table>
</body>
</html>
imagen donde llegan primera vez $_POST para verificar datos introducidos

segunda imagen donde claramente no llegan las variables $_POST....

Valora esta pregunta


0