There seems to be some kind of error when I try connecting to the database, I checked to make sure the credentials were correct, I tried importing it from another file, but that did not help either. the error shows up on $conn = new mysqli($dbhost,$dbuser,$dbpassword,$db) or die("connection failed: %s\n". $conn->error); any suggestions?

        // creating the connection to database
          $dbhost="localhost";
          $dbuser = "Mydatabase";
          $dbpassword="123";
          $db="userweight";

          // connecting to the database 
          $conn = new mysqli($dbhost,$dbuser,$dbpassword,$db) or die("connection failed: %s\n". $conn->error);

          // creating the table 
          $table="CREATE TABLE Users(
            id INT(0) PRIMARY KEY,
            FirstName VARCHAR(50) NOT NULL,
            LastName VARCHAR(50) NOT NULL,
            Password  VARCHAR() NOT NULL,
            EMAIL   VARCHAR ()  NOT NULL
          )";

         if($conn->query($table) === TRUE){
           echo"Table created successfully";
          }else{
            echo "Error creating table: " . $conn->error;
          }
        $conn->close();
          ?>

EDIT 1

The error i'm getting:

Warning: mysqli::__construct(): (HY000/1044): Access denied for user 'Mydatabase'@'localhost' to database 'userweight' in C:\xampp\htdocs\Weight-tracker\signup.php on line 64


EDIT 2

The privileges for [email protected] were not granted, that was the problem. Granting the privileges fixed the problem!

0 Answers