所以我正在创建一个名为Dabox的社交网络!并编制了一份登记表。我通过输入用户名,密码和电子邮件来测试它。
我将用户名作为测试,我的密码在测试时发送,并将电子邮件发送至test@dabox.xyz。我测试了它,它出现了:
INSERT INTO用户(用户名,密码,电子邮件)VALUES(' test',' test',' test@dabox.xyz') SQLSTATE [23000]:完整性约束违规:1062重复条目''关键' PRIMARY'。
我的代码是:
<?php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "daboxdb";
$user = ($_POST['user']);
$pass = ($_POST['pass']);
$mail = ($_POST['email']);
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO users (username, password, email)
VALUES ('$user', '$pass', '$mail')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
我不知道问题所在。你能救我吗?
答案 0 :(得分:0)
检查 ID 列,该列将作为主键。您尝试插入重复数据