php - 在我的 php 登录系统中检查重复的用户名
问题描述
尝试为我的用户设置一个面板以查看仅限登录的内容,我目前遇到一个问题,人们可以使用相同的用户名/电子邮件注册任何人都知道如何解决这个问题我尝试了几行不同的代码建议?
这是我当前的 signup.php
<?php
require_once 'source/db_connect.php';
if(isset($_POST['signup-btn'])) {
$username = $_POST['user-name'];
if($username == '' || empty($username)){
echo "<body style='background-color:#212121'><br><br><br><br><br><br><br><br><br><br><br><br><center><font size='12' color='red'>Username cannot be blank..</font></center> <br><br><br> <center><a href='register.html'><font size='5'>Click To Return.</font></a></body>";
return false;
}
$email = $_POST['user-email'];
if(strpos($email, '@') == false || strpos($email, '.') == false){
echo "<body style='background-color:#212121'><br><br><br><br><br><br><br><br><br><br><br><br><center><font size='12' color='red'>Invalid Email Adress..</font></center> <br><br><br> <center><a href='register.html'><font size='5'>Click To Return.</font></a></body>";
return false;
}
$password = $_POST['user-pass'];
if($password == '' || empty($password)){
echo "<body style='background-color:#212121'><br><br><br><br><br><br><br><br><br><br><br><br><center><font size='12' color='red'>Password cannot be blank..</font></center> <br><br><br> <center><a href='register.html'><font size='5'>Click To Return.</font></a></body>";
return false;
}
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
try {
$SQLInsert = "INSERT INTO users (username, password, email, to_date)
VALUES (:username, :password, :email, now())";
$statement = $conn->prepare($SQLInsert);
$statement->execute(array(':username' => $username, ':password' => $hashed_password, ':email' => $email));
if($statement->rowCount() == 1) {
header('location: success.html');
}
}
catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
解决方案
推荐阅读
- python - matplotlib用极坐标绘制pdf错误
- python - 删除张量切片作为 TensorFlow 层的一部分
- c# - 在 C# 中编写异步方法的最佳方法
- javascript - 使用 beforeEnter 传递数据以路由组件
- r - dplyr:总结,找不到对象
- python - 文件位于不同文件夹时导入模块时出现问题
- activerecord - 向对象的 ActiverecordRelation 添加方法
- mongodb - Mongoose 文档类型声明
- python - 评估模型时出现“太多值无法解包(预期为 2)”错误
- python - 从 (1,2) pytorch 张量生成模型的置信度