Jump to content

In Shopping Cart App. Error Message


chamari

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

 

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...