Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Jake White
Jake White
41,730 Points

PHP User Login System Help

So after searching the web for weeks and weeks for a good tutorial, something registered in my head, "Maybe GitHub has one that someone else has already built and tested!"

Sure enough I found one here https://github.com/TazChris/phpUserLoginSystem and it looks great. I was trying to implement it into my site and I get this issue

Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL server host 'login' (0) in /Applications/MAMP/htdocs/controller/classes/AuthDB.class.php on line 8

Warning: mysqli::prepare(): Couldn't fetch mysqli in /Applications/MAMP/htdocs/controller/classes/AuthDB.class.php on line 21

Fatal error: Call to a member function bind_param() on a non-object in /Applications/MAMP/htdocs/controller/classes/AuthDB.class.php on line 27

I think the issue is coming from the config.php file that is being required_once at the top of the AuthDB.class.php file. Right now I'm using MAMP. I have a database named login with the tables already set up with file included with the download. My code for the config.php file is set up like this

<?php
  //Database information
  define("DB_SERVER", "localhost");
  define("DB_USER", "root");
  define("DB_PASS", "root");
  define("DB_NAME", "localhost");
  //Database table information 
  define("USER_TABLE", "tbUsers");
  define("LOGGED_IN_TABLE", "tbLoggedInUsers");
  //Fully Qualified Domain Name
  define("SITE_HTTP", "http://localhost:8888");
  //Return email address
  define("FROM_EMAIL", "");
?>

Any ideas on what I might be doing wrong?

Hi Jake, can you tell me exactly what type of functionality you are looking for in your php member system?

1 Answer

It sounds like from the error that somewhere else you've got your DB_SERVER set to login instead of localhost as it should be.

Also, it looks like in your config.php that DB_NAME should be set to login instead of localhost as it is above.