-1

so i am making my first website and im trying to connect to my mysql databaste running on apache server via xaamp

My code is below and the errors it is giving when i try to login, a screenshot of the database is also attached

   include("config.php");
   session_start();

   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 

      $myusername = mysqli_real_escape_string($db,$_POST['username']);
      $mypassword = mysqli_real_escape_string($db,$_POST['password']); 

      $sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
      $result = mysqli_query($db,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
      $active = $row['active'];

      $count = mysqli_num_rows($result);

      // If result matched $myusername and $mypassword, table row must be 1 row

      if($count == 1) {
         session_register("myusername");
         $_SESSION['login_user'] = $myusername;

         header("location: index.html");
      }else {
         $error = "Your Login Name or Password is invalid";
      }
   }
?>

config.php:

   define('DB_SERVER', '127.0.0.1');
   define('DB_USERNAME', 'root');
   define('DB_PASSWORD', 'rootpassword');
   define('DB_DATABASE', 'database');
   $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>

error:

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in D:\xampp\htdocs\Website\Websiteassesment\config.php on line 6

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, bool given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 8

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, bool given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 9

Warning: mysqli_query() expects parameter 1 to be mysqli, bool given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 12

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 13

Notice: Trying to access array offset on value of type null in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 14

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 16

any help would be appreciated

Quinny
  • 1

1 Answers1

-1

The error means your mySQL login credentials are incorrect. Check if the username root and password rootpassword are correct.

djunehor
  • 941
  • 7
  • 9
  • correct where? sorry im really new to this – Quinny Apr 22 '20 at 04:06
  • Your DB login details are defined in `config.php`. The error means the details are not correct. If you're on a local environment i.e your computer, the password might be an empty string, so modify to `define('DB_PASSWORD', '');` – djunehor Apr 22 '20 at 04:11