Jump to content
Killersites Community
Sign in to follow this  
chamari

In Shopping Cart App. Error Message

Recommended Posts

In the categories php I am getting the following error. I checked the syntax with the finished file and its correct.

 
				( ! ) Fatal error: Call to a member function prepare() on a non-object in C:\wamp\www\source\phpcartoopmvc-empty-projectfiles\app\models\m_categories.php on line 35						Call Stack						#							Time							Memory							Function							Location						1							0.0006							669736							{main}( )							..\index.php:0						2							0.0039							727112							Categories->get_categories( )							..\index.php:4
 

				( ! ) Fatal error: Call to a member function query() on a non-object in C:\wamp\www\source\phpcartoopmvc-empty-projectfiles\app\models\m_categories.php on line 54						Call Stack						#							Time							Memory							Function							Location						1							0.0007							669616							{main}( )							..\index.php:0						2							0.0160							726936							Categories->get_categories( )							..\index.php:4
 
It is the same whether I pass a category or not. I think its not connecting to the database.
Connection script in the init.php

//Connect to database
$server = 'localhost';
$user = 'root';
$pass = '';
$db = 'ks_shop';
$Database = new mysqli($server, $user, $pass, $db);

Please help

 

Share this post


Link to post
Share on other sites

Hi,

 

The error says:

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

That suggest to me a simple coding error - your calling query() without associating the code/call to an object.

 

So in the code snippet above, I see that you are creating an instance of the mysqli object:

$Database = new mysqli($server, $user, $pass, $db);

Can you show us the code where you are executing the query?

 

Stef

Share this post


Link to post
Share on other sites

An error related to a database query and a "non-object" usually means that the $Database object isn't being correctly created -- usually due to a incorrect username or password. If you are using MAMP on a Mac, the username is "root" and the password is empty. If you are using WAMP, the username is "root" and the password is "root".

 

If you are using XAMPP, check the documentation for the correct login info. If you are running this on live web hosting, not on your computer, then talk to support about the correct username/password combination.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×