我有下面的代码来检查 username
已经用过了,我还需要用4个字段。
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql2 = "SELECT * FROM users WHERE username = ?";
$q2 = $pdo->prepare($sql2);
$q2->execute(array($username));
$result = $q2->fetchAll();
if (count($result) > 0) {
$usernameError = 'O utilizador já existe!';
}
else{
$sql = "INSERT INTO users (username,password,role) values(?, ?, ?)";
$q = $pdo->prepare($sql);
$q->execute(array($username,$password,$role));
header("Location: index.php");
}
Database::disconnect();
}
1条答案
按热度按时间q3qa4bjr1#
如果您需要知道哪些字段已经复制,请使用以下方法:
然后可以为结果中等于的每列生成相应的错误消息
1
.