我正在为学校办理登录/注册表格,但我遇到了问题。
如果您使用数据库中已存在的用户名(我已使用UNIQUE KEY作为用户名),如何给出错误消息
提前感谢任何答案:)祝你有愉快的一天
<?php
error_reporting(E_ALL & ~E_NOTICE);
session_start();
if ($_POST['submit']) {
// check if passwords match
if ($_POST['password'] == $_POST['confirmpassword']) {
include_once("connect.php");
$username = $dbCon->real_escape_string($_POST['username']);
$password = ($_POST['password']);
$sql = "INSERT INTO members (username, password, activated) "
."VALUES ('$username', '$password', '1')";
// if registration succesful, send to user.php, if not, error message
if ($dbCon->query($sql) === true) {
header('Location: user.php');
echo "Registration succesful, Welcome $username";
exit;
} else {
echo "Could not register, please fill in both username and password";
}
} else { // if the passwords do not match
echo "Lösenorden matchar inte!";
}
}
?>