我有一个HTML表单,我使用PHP将结果发送到phpMyAdmin上的sql数据库但是在提交后我得到了#34;用户访问被拒绝' root' @&## 39;本地主机' (使用密码:是)"错误。
这是使用MAMP本地托管的,root @ localhost是唯一的用户,我确定我有正确的密码。
我查看了类似的问题,刷新了权限,创建了新用户,尝试通过命令行登录(我得到了相同的错误),但似乎没有任何效果。
这是我的代码:
$hostname = "localhost";
$username = "root";
$password = "root";
$dbname = "quotetool";
$conn = new mysqli($hostname, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO customerdetails (workstations, servers, firewalls, name, email, phone, support)
VALUES ('$workstations', '$servers', '$firewalls', '$name', '$email', '$phone', '$support')";
if ($conn->query($sql) === TRUE) {
echo "New record created";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
如果这有帮助,这是我的用户
答案 0 :(得分:0)
尝试使用此代码可能是因为MySql希望Mamp使用端口3306。
$hostname = "localhost";
$username = "root";
$password = "root";
$dbname = "quotetool";
$port = "8889";
$conn = new mysqli($hostname, $username, $password, $dbname, $port);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO customerdetails (workstations, servers, firewalls, name, email, phone, support)
VALUES ('$workstations', '$servers', '$firewalls', '$name', '$email', '$phone', '$support')";
if ($conn->query($sql) === TRUE) {
echo "New record created";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
更正语法
mysqli_connect(host,username,password,dbname,port,socket);
如果有任何问题让我知道,我会尝试修复它。