Error Encountered: Attempting to invoke a method on a variable that is not an

function finishGame($outcome) {

    $query = "UPDATE stats SET outcome = ? WHERE id = ?";
    
    $statement = $this->connection->prepare($query);
    $statement->bind_param("si", $outcome, $this->currentSession);//Issue here
    $statement->execute();
    $statement->close();
}

mysql> describe games;
+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| id          | int(12)     | NO   | PRI | NULL    | auto_increment |
| name        | varchar(20) | NO   |     | NULL    |                |
| date_played | datetime    | NO   |     | NULL    |                |
| difficulty  | tinyint(4)  | YES  |     | NULL    |                |
| outcome     | varchar(20) | NO   |     | NULL    |                |
+-------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

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

I can't figure out the mistake causing the non-object error despite knowing it's likely related to my SQL query.

Answer №1

Please make sure to include the complete error message in your post.

It seems likely that the issue, as pointed out by Andomar, is that $stmt is being treated as an error rather than a statement object.

Answer №2

After some investigation, I discovered the issue. It turns out that the user account I set up to connect to the database was lacking the necessary permissions.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Laravel has not been properly initialized

Recently, I've been exploring Laravel 5.3 and vue.js and I'm trying to make a GET request to fetch some user data from my database. I'm utilizing components in this project. Here is a snippet from my app.js file: require('./bootstrap ...

AJAX request fails to invoke upload.php script

After selecting an image, adding some text, and clicking submit, the progress bar shows that the upload was successful. However, the upload.php file is not being called as expected. Question: What could be causing the issue in my code that is preventing t ...

Converting Time from a String to Numerics in PHP and MySQL

Currently, I'm working on creating a visual representation of drill times for my project. Within the database, drill durations are stored as Time fields. When retrieved, the times are in MM:SS format (e.g., 05:30). The graphing package I've sele ...

In PHP, the hidden input type doesn't always provide true concealment within a form if the value being passed

I am attempting to populate a hidden input field with the value of an XML string generated from an array. However, when I set the hidden field value using the XML string, it is being displayed in the HTML output. Surprisingly, if I use plain text as the va ...

Refresh the PHP MySQL table view based on selection changes in the dropdown menu

Hello there! I currently have a table displayed on my page thanks to the following code: $result = mysql_query("Select * from porders, porders_detail, parts where porders.order_no = porders_detail.order_no and porders_detail.om_part_no = parts.om_part_no" ...

If the AJAX call takes too long to return, it may not return any data

I am managing a large database with over 1000 entries, and the data size is expected to grow further. To display a subset of this data in a table, I have implemented a search feature using AJAX calls to load data dynamically based on user input. Here is ...

Subdirectory configuration with Nginx and php-fpm

My goal is to run php-fpm using nginx, with different roots specified for different locations: for path: http://localhost/ -> /usr/share/nginx/html http://localhost/pma -> /var/www/default/phpMyAdmin/ http://localhost/pga -> /var/www/default/php ...

Is it possible to transfer data from javascript to php through ajax?

I am attempting to extract the data speedMbps from my JavaScript code using Ajax to send the data to my PHP script, but unfortunately, I am not receiving any output. My experience with Ajax is limited to implementing auto-completion feature. <script sr ...

Transform the JSON data into an array

I am attempting to save the titles in an array and retrieve the lengthy cmcontinue string from the following URL. http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:1980_births&format=json Here is my current ...

Class for Laravel Authentication

For Laravel's auth class to function properly, is it necessary to have a database? Does this apply even if the server itself already has its own authentication process in place? I'm interested in utilizing Laravel's Auth class methods to de ...

Incorporating a user ID (foreign key) into a MySQL table using NextJS and Prisma

Currently, I am in the process of developing an online recipe platform that allows users to log in and share their recipes. The technology stack I am using includes NextJS, Prisma, and MySQL DB. User authentication is handled with NextAuth and a credential ...

Error encountered while trying to add foreign keys in MySQL database

When attempting to add a foreign key to my Table using the following query: $query = "ALTER TABLE reserved ADD CONSTRAINT fk_test FOREIGN KEY (personel_num) REFERENCES members (personel_num) ON DELETE CASCADE ON UPDATE;"; if ($conn->query($query) === T ...

The WooCommerce mini cart fails to refresh after items are added using AJAX

I have successfully implemented adding multiple items with quantities to the cart using AJAX. However, after adding a product, the mini cart is not updating as expected. I am calling WC_AJAX::get_refreshed_fragments() in my function.php and have a hook set ...

Struggle with incorporating a file

As part of the login process, I have two options available: easy login and standard login. The easy login requires an employee ID, birthdate, and captcha answer, while the standard login asks for first name, last name, birthdate, and captcha. To facilitate ...

If there is a discrepancy between the billing and shipping addresses, it is recommended to put a WooCommerce order on hold

I am looking for a solution to combat fraud on my WooCommerce website. Oftentimes, scammers use automated bots with stolen credit card information to make purchases and have the products shipped to a different address than the billing one. To prevent this, ...

PHP/jQuery search field

I am currently working on creating a search box using php and jquery to retrieve search results from a database. My goal is to have the search query triggered as the user types into the search box, finding data that matches the keywords entered by the user ...

Optimal Placement for FB.Event.subscribe

Here is the code I have implemented on my website for the Facebook Like and Share buttons. The functionality works seamlessly. When I click the Like button, a notification is promptly displayed on my Facebook profile page. Additionally, Facebook automatic ...

Automating web pages with the power of Node.js

I have developed an API in PHP that accepts a 10-digit number as a variable and provides data in JSON format. For instance, the URL structure is like this: www.exampletest.com/index.php?number=8000000000. The succeeding variable will be the current number ...

Tips for showcasing multiple tables based on certain criteria

Hey there, I'm currently working on an inventory page where I want to display multiple tables based on department values. The goal is to have each department in its own table instead of all merged into one. It would definitely make the page easier to ...

Tips for retrieving data from an AJAX request and utilizing it within a PHP conditional statement

I am attempting to create an ajax post request that extracts the value of a radio button and utilizes it within a PHP conditional statement. Here is the code I have tried so far (all code is included in one php file): $(document).ready(function () { $ ...