-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
73 lines (61 loc) · 2.59 KB
/
signup.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>error</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
</head>
<body>
</body>
</html>
<?php
$conexion = mysqli_connect("sql302.byethost13.com", "b13_36951409", "benjamin5");
$consulta1=mysqli_select_db($conexion, "b13_36951409_proyecto");
$nombre = $_POST['name'];
$correo = $_POST['email'];
$contraseña = $_POST['pass'];
$confirm_contraseña = $_POST['confirm_pass'];
if ($contraseña !== $confirm_contraseña) {
die("Las contraseñas no coinciden.");
}
// Verificar si el nombre de usuario ya existe
$check_nombre = "SELECT * FROM usuario WHERE nombre='$nombre'";
$result_nombre = mysqli_query($conexion, $check_nombre);
// Verificar si el correo electrónico ya existe
$check_correo = "SELECT * FROM usuario WHERE correo='$correo'";
$result_correo = mysqli_query($conexion, $check_correo);
if ((mysqli_num_rows($result_nombre) > 0) and (mysqli_num_rows($result_correo) > 0)) {
echo "<h2>El nombre de usuario y el correo electrónico ya estan en uso.</h2>"; ?>
<br>
<a href="signup_html.php" class="btn btn-secondary">Volver a Intentar</a>
<a href="login_html.php" class="btn btn-success">Iniciar Sesion</a>
<?php
die; }
if (mysqli_num_rows($result_nombre) > 0) {
echo "<h2>El nombre de usuario ya está en uso.</h2>"; ?>
<br>
<a href="signup_html.php" class="btn btn-secondary">Volver a Intentar</a>
<a href="login_html.php" class="btn btn-success">Iniciar Sesion</a>
<?php
die; }
if (mysqli_num_rows($result_correo) > 0) {
echo "<h2>El correo electrónico ya está en uso.</h2>"; ?>
<br>
<a href="signup_html.php" class="btn btn-secondary">Volver a Intentar</a>
<a href="login_html.php" class="btn btn-success">Iniciar Sesion</a>
<?php
die; }
$pass = password_hash($contraseña, PASSWORD_BCRYPT);
$sub = isset($_POST['subscribe']) ? 1 : 0;
$consulta = "INSERT INTO usuario (nombre, correo, contrasena, sub)
VALUES ('$nombre', '$correo', '$pass', '$sub')";
if (mysqli_query($conexion, $consulta)) {
header('Location: login_html.php');
exit();
} else {
echo "Error: " . $consulta . "<br>" . mysqli_error($conexion);
}
mysqli_close($conexion);
?>