PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 14, 2022

[FIXED] Access denied for user 'root'@'localhost' (using password: YES) using MAMP server

 March 14, 2022     mamp, mysql, php, phpmyadmin, sql     No comments   

Issue

I have a HTML form and I'm using PHP to send the results to an sql database on phpMyAdmin but after submitting I get "Access denied for user 'root'@'localhost' (using password: YES)" error.

This is all hosted locally using MAMP, root@localhost is the only user and I'm sure I've got the right password.

I've looked through similar questions, flushed privileges, created new users, tried logging on through the command line (to which I get the same error) but nothing seems to work.

Here's my code:

$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();

and here is my user if this helps

enter image description here

Screenshot of my error


Solution

Try this code possibly it is because MySql expects Mamp to use port 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();

Correct syntax

mysqli_connect(host,username,password,dbname,port,socket);

If any issue let me know I will try fixing it.



Answered By - Rajendran Nadar
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing