php - Fatal error: Call to a member function query() on a non-object Error -


i have small problem. i'm trying make simple register/login system sessions , got error:

fatal error: call member function query() on non-object in c:\xampp\htdocs\members\includes\login.inc.php on line 9

this relevant line of code:

$result = $conn->query($sql); 

the first time tried working.

the rest of code:

<?php if ($_server['request_method'] == 'post') {     $email      = $_post['email'];     $password   = md5($_post['password']);     $sql = "select email, password member email = '$email' , password = '$password'";     $result = $conn->query($sql); 

i have db.php, used connect mysql , inside fine.

i cannot understand why, first time tried working guess , kind of error.

i'm having db.php used connect mysql , inside fine.. explain me why keep facing error ?

i'm going speculate. i'm speculating have separate file (probably called db.php) "handles" setting of database connection. i'm further going speculate you've chain of files require() (or include())'d web app.

i've seen more times care recall. it's old fashioned way of separating code logical chunks inside php - needs left in past.

i'm speculating defining $conn in script included (or required) before code. global variable, had dependency later in code execution. invisible file declared in.

that's problem. quick/hack fix rename $conn or restore original declaration of , make sure it's global , make sure included before code ran.

the proper fix (imho) @ using framework (laravel, lumen, codeigniter, yii, there many - take pick) , read on topics of dependency injection, autoloading , namespacing. think why global variable declarations make unmaintainable code.

if you're reluctant go full framework, @ least have @ database-abstraction libraries doctrine (and it's sub-library dbal) can auto-loaded project via composer.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -