将失败的信息插入数据库



我不知道为什么要传递它,连接很好,我的表有usuariocontraseña,数据库的名称也是Usuarios我把提交的信息放在表格中,它不会在数据库中标记我的错误。

此外,我看到了所有的代码,并且在插入数据的代码中没有发现错误。

我可以说的另一件事是,我用来建立连接的方法是PDO

<?php
require "./php/conectar.php";
$message = '';
if (!empty($_POST['usuario']) && !empty($_POST['contraseña'])) {
$sql = "INSERT INTO usuarios (usuario, contraseña) VALUES (:usuario, :contraseña)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':usuario',$_POST['usuario']);
$password = password_hash($_POST['contraseña'], PASSWORD_BCRYPT);
$stmt->bindParam(':contraseña',$_POST['contraseña']);
}
?>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login</title>
<link rel="stylesheet" href="css/login.css" />
<link
href="https://fonts.googleapis.com/css2?family=Baloo+Paaji+2:wght@400;700&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="login.js" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous"
/>
</head>
<body>
<!-- Formulario Inicio de sesión -->
<div class="container mt-5">
<div class="row justify-content-center">
<div class="formulario col-md-6">
<h2 class="font-weight-light text-center mb-4">Iniciar sesion</h2>
<form class="" action="login.php" method="POST">
<div class="form-group">
<label for="exampleInputEmail1">Dirección de email</label>
<input
maxlength="30"
class="form-control form-control-lg"
type="text"
name="usuario"
id="usuario"
placeholder="Usuario"
required
/>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Contraseña</label>
<input
maxlength="30"
class="form-control form-control-lg"
id="contraseña"
name="contraseña"
type="password"
placeholder="contraseña"
required
/>
</div>
<input
class="form-control form-control-lg bg-primary font-weight-bold text-white"
id="signin"
type="submit"
value="Iniciar sesión"
/>
</form>
</div>
</div>
<div class="text-center reset-password">
<a href="#" class="font-weight-bold">¿Olvidaste tu contraseña?</a>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"
></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"
></script>
</body>
</html>

我更改了它的代码(也是表单中的代码(,但它不起作用

if (!empty($_POST['usuario']) && !empty($_POST['password'])) {
$sql = "INSERT INTO users (email, contrasena) VALUES (:email, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':email', $_POST['email']);
$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':password', $password);
$stmt->execute();
}

最新更新