Skip to content

Commits on Source 2

...@@ -7,8 +7,10 @@ $password = $_POST['registerPassword']; ...@@ -7,8 +7,10 @@ $password = $_POST['registerPassword'];
$confirm_password = $_POST['confirm_password']; $confirm_password = $_POST['confirm_password'];
$tipo_usuario = $_POST['tipo_usuario']; $tipo_usuario = $_POST['tipo_usuario'];
$query = "SELECT * FROM usuarios WHERE email='$email'"; $stmt = $conn->prepare("SELECT * FROM usuarios WHERE email = ?");
$result = mysqli_query($conn, $query); $stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
if (mysqli_num_rows($result) > 0) { if (mysqli_num_rows($result) > 0) {
header("Location: registro.php?mensaje_error=El correo ya está en uso, por favor elige otro."); header("Location: registro.php?mensaje_error=El correo ya está en uso, por favor elige otro.");
...@@ -17,14 +19,23 @@ if (mysqli_num_rows($result) > 0) { ...@@ -17,14 +19,23 @@ if (mysqli_num_rows($result) > 0) {
header("Location: registro.php?mensaje_error=Las contraseñas no coinciden, por favor verifica."); header("Location: registro.php?mensaje_error=Las contraseñas no coinciden, por favor verifica.");
} else { } else {
$password_hash = password_hash($password, PASSWORD_BCRYPT); $password_hash = password_hash($password, PASSWORD_BCRYPT);
$query = "INSERT INTO usuarios (nombre, email, password, tipo_usuario) VALUES ('$nombre', '$email', '$password_hash', '$tipo_usuario')";
if (mysqli_query($conn, $query)) { $stmt = $conn->prepare("INSERT INTO usuarios (nombre, email, password, tipo_usuario) VALUES (?, ?, ?, ?)");
header("Location: registro.php?mensaje=Registro exitoso.."); if(!$stmt) {
header("Location: registro.php?mensaje_error=Error en la consulta de inserción.");
exit();
}
$stmt->bind_param("ssss", $nombre, $email, $password_hash, $tipo_usuario);
if($stmt->execute()){
header("Location: registro.php?mensaje=Registro exitoso.");
} else { } else {
header("Location: registro.php?mensaje_error=Error al registrarse."); header("Location: registro.php?mensaje_error=Error al registrarse.");
} }
$stmt->close();
} }
} }
$conn->close(); $stmt->close();
?> ?>
...@@ -99,8 +99,8 @@ ...@@ -99,8 +99,8 @@
<input type="text" class="form-control" id="registerName" name="registerName" required> <input type="text" class="form-control" id="registerName" name="registerName" required>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for "registerEmail" class="form-label"><i class="fas fa-envelope"></i> Correo electrónico</label> <label for="registerEmail" class="form-label"><i class="fas fa-envelope"></i> Correo electrónico</label>
<input type="email" class="form-control" id="registerEmail" name "registerEmail" required> <input type="email" class="form-control" id="registerEmail" name="registerEmail" required>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="registerPassword" class="form-label"><i class="fas fa-lock"></i> Contraseña</label> <label for="registerPassword" class="form-label"><i class="fas fa-lock"></i> Contraseña</label>
......