
El codigo PHP no guarda datos.
Publicado por JSevilla (1 intervención) el 12/10/2020 16:20:19
Esto se supone que deberia guardar datos, y no lo hace. La conexión a la base de datos funciona correctamente.
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
<?php
$servidor="localhost";
$usuario="Confidencial";
$clave="Confidencial";
$baseDeDatos="id15086415_jsevillainc";
$enlace = mysqli_connect($servidor, $usuario, $clave, $baseDeDatos);
if(!$enlace){
echo"Error en la conexion con el servidor";
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JSevilla Inc</title>
<link rel="stylesheet" href="estilo.css" type="text/css" media="screen">
<script>
function solonumeros(e){
tecla = (document.all) ? e.keyCode : e.which;
if (tecla==8) return true;
patron = /[0-9]/;
te = String.fromCharCode(tecla);
return patron.test(te);
}
</script>
</head>
<body>
<form method="POST">
<div class="Formulario1">
<label>Nombre</label><br>
<input type="text" name="nombre" required="required" maxlength="20" size="50"><br><br>
<label>Apellidos</label><br>
<input type="text" name="apellidos" required="required" maxlength="20" size="50"><br><br>
<label>Número de documento</label><br>
<input type="text" name="documento" required="required" maxlength="15" onKeyPress="return solonumeros(event)" size="50"><br><br>
<label>Correo electronico</label><br>
<input type="email"name="correo" required="required" maxlength="20" size="50"><br><br>
<label>Número de contacto</label><br>
<input type="tel" name="telefono" required="required" maxlength="10" onKeyPress="return solonumeros(event)" size="50"><br><br>
<label>Sexo</label><br>
<div>
<input type="radio" name="sexo" id="Hombre" value="Hombre">
<label>Hombre</label>
<input type="radio" name="sexo" id="Mujer" value="Mujer">
<label>Mujer</label>
</div><br>
<input type="submit" class="btn" name="registrarse" value="Registrate">
</form>
</div>
</body>
</html>
<?php
if(isset($_POST['registrarse'])){
$id= rand(1,99);
$nombre= $_POST["nombre"];
$apellidos= $_POST["apellidos"];
$documento= $_POST["documento"];
$correo= $_POST["correo"];
$numero_contacto= $_POST["telefono"];
$sexo= $_POST["sexo"];
$insertardatos = "INSERT INTO new_users VALUES('$id','$nombre','$apellidos','$documento','$correo','$numero_contacto','$sexo')";
$ejecutarinsertar = mysqli_query($enlace, $insertardatos);
if(!$ejecutarinsertar){
echo "Error en la conexión.";
}
}
?>
Valora esta pregunta


0