0

When ever users click on the submit button on my website to submit an entry, they get redirected to a different page with the feedback:

Connection Failed:Access denied for user 'root'@'localhost' (using password: NO)

The database is called 'circlecu_resultorientedmarket' and the table is named 'registration'.

$name = $_POST['Name'];
$phone = $_POST['Phone'];
$email = $_POST['Email'];
$message = $_POST['Message'];

$conn = new mysqli('localhost','root','','circlecu_resultorientedmarket');
if($conn -> connect_error){
    die('Connection Failed:'.$conn->connect_error );
}else{
    $stmt = $conn->prepare("insert into registration(Name, Phone, Email, Message)
    values(?,?,?,?)");
    $stmt ->bind_param("ssss",$name,$phone,$email,$message);
    $stmt -> execute();
    $stmt->close();
    $conn->close();

    echo "<h2>Thank you,  $name </h2>";
   echo '<p style="font-size:20px;">Your account has been created successfully</p>';
}
?> ```

How can I resolve this error?
Dharman
  • 30,962
  • 25
  • 85
  • 135
Tgimba1
  • 11
  • 2
  • You really should not be connecting to your database via root, and it most likely has a password. Double-check your mysql credentials on your server for that database, and enter it into your code. – aynber Apr 11 '22 at 16:23

1 Answers1

-2

You have to add a password to mysql fist. for some security reasons you can not empty the password.

if you have installed mysql your own on linux/centos, this guide could help you. continue from :

 mysql_secure_installation