What could be causing this prepared statement to consistently display -1 rows affected?

I'm really struggling with this mysqli prepared statement and I just can't seem to figure out what's going wrong. I've spent a lot of time troubleshooting already, so let me start by showing you the code snippet (which is currently only working locally):

$link = mysqli_connect("localhost", "root", "", "dbName");

if($stmt = $link->prepare("INSERT INTO created_memes (created_meme_fileName, created_meme_title, created_meme_likes, created_meme_datePosted) VALUES (?, ?, ?, ?)")){
    $stmt->bind_param('sssd', $fileName, $title, $likes, $datePosted);

    $title = $_POST["memeTitle"];
    $likes = 0;
    $dataPosted = date("Y-m-d H:i:s");


    $stmt->execute();

    printf($stmt->affected_rows);

    echo "Connection established; query was not successful.";

    $stmt->close();

} else {
    echo "Connection failed.";
}

Let me quickly summarize:

The $fileName variable is set earlier in the code, so that's not the problem. Even when I tried redefining it alongside the other variables, I still ended up with -1 rows affected.

I even attempted setting all the variables as static strings to rule out any issues with them, but still no luck.

I've double, triple, quadruple checked the connection details, table name, and column names; they are all accurate.

I've tested this with the current if statement you see, and also without it. Unfortunately, neither approach worked.

I experimented with placing bind_param before and after defining the variables, thinking it might make a difference. It didn't help either.

At this stage, I feel like I've exhausted all options and I'm at a loss. Any help or guidance would be greatly appreciated!

Answer №1

According to information from the manual:

If returns -1 it means that there was an error in the query.

You can use echo $stmt->error; to identify the issue.

My assumption is that the error occurred because you are trying to insert 5 pieces of data into a table that only has space for 4 fields.

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

RegEx pattern for setting DirectoryIndex in htaccess

Apologies if this topic has been discussed before regarding .htaccess, but I have yet to find a clear answer to my specific questions. Here are the issues I am facing: 1. My goal is to eliminate index.php from URLs both in the home directory and subdirecto ...

Instructions on submitting a form containing multiple select lists using the enter key

After researching various threads, I have come across solutions using the JS onkeypress function to trigger actions with input fields. However, in my case, I need to implement this functionality with a form that consists of multiple select lists instead of ...

Error found - PHP if condition inside HTML td element

Whenever I open my browser, I encounter this error message: Parse error: syntax error, unexpected 'if' (T_IF) I have been working on creating an HTML table to display prices for a Woocommerce product. Although I've come across similar issu ...

Having trouble with Installing ownCloud on Raspberry Pi

Every time I attempt to open ownCloud, an error message appears stating: PHP module mb multibyte not installed. Please ask your server administrator to install the module. PHP modules have been installed, but they are still listed as missing? Please ask y ...

Tips for resolving an error in PHP and MYSQL code where data is being selected from the incorrect table in the database

I am working on a PHP code with MYSQL. It involves selecting data from the database using a dropdown list with AJAX and displaying the results on the screen. I have three dropdown lists that are dependent on each other and each dropdown has its own table t ...

Select a particular item and transfer its unique identifier to a different web page. Are there more efficient methods to accomplish this task without relying on href links and using the $_GET

Could there be a more efficient method for transferring the ID of a specific motorcycle from index.php to inventory.php when it is clicked on, aside from using href and $_GET? Perhaps utilizing hidden fields or submitting a form through JavaScript? What ...

Utilize the power of Javascript/AJAX or jQuery to submit multiple forms simultaneously

I am currently working on a project which involves having 3 forms on a single page. The reason behind this is that one of the forms is displayed in a modal dialog. My goal is to allow users to submit all 3 forms with a single button click, and I also wan ...

Prevent image swapping when selecting variations in Woocommerce

Can the image change be disabled when selecting a variation for a variable product? I understand that I could remove the image from the variation, but in my situation, I need to keep the variation images. Any assistance would be greatly appreciated. ...

Does AWS offer a solution for monitoring failed Python scripts with an alarm system?

I am looking for a system that can verify the successful completion of multiple Python scripts. These scripts are responsible for scraping data and saving it in XML files. In case of failure, there may be missing XML files or error messages in the logs. ...

Having trouble with PHP when using JQuery Ajax to post data

Currently, I am working with a list of records retrieved from a MySQL table. Each record has been assigned an onclick function to pass data for further database queries without having to refresh the page. <a href='javascript:void(0)' onclick= ...

Creating a dynamic JQuery navigation menu directly from a MySQL database table

I am looking to dynamically populate the menu on this website (http://www.hv-designs.co.uk/tutorials/sliding_menu/sliding_menu.html) with values from a MySQL table. Essentially, when the user clicks on the top menu button, I want the menu items to be rows ...

Managing numerous ajax forms within a single page

Upon receiving advice from the following inquiry Multiple forms in a page - loading error messages via ajax, I am endeavoring to incorporate multiple forms within one page. The goal is to insert error messages into the corresponding input div classes. I pr ...

Can a div section be defined and then filled with data in the same document?

Is it possible to initially declare a div section and later populate it with content in the same document? The following dummy code snippet illustrates the query... <div name="xyz" style="..."> <!-- Empty --> </div> < ... INTO "x ...

Updating an element within a JSON object in PHP: A step-by-step guide

I have a JSON object that looks like this: { "fields" : [ { "name" : "news_title", "type" : "text", "value" : "old title" }, { "name" : "news_co ...

PHPMailer is giving me trouble as emails are not showing up in my Gmail inbox

For a while, I was receiving emails without any issues but suddenly they stopped coming in. I'm not sure what went wrong with my code and there are no error logs to refer to as well. This issue is occurring on my GoDaddy server. $mails = new PHPMaile ...

Issues encountered while retrieving JSON data from a URL using port 88

There is a URL for IPTV that returns JSON data. The URL will expire after 24 hours, so there's no risk of misuse. http://mytv-extra.com:88/player_api.php?username=4240670294&password=0301902562&action=get_live_streams&category_id=3045 Wh ...

What is the best way to compare a JSON object with a string in an Android application?

Here is the code snippet that functions correctly by displaying content when the EditText field is left blank or contains a string value present in the MySQL database. However, I am facing an issue where I want to show an error message when the input from ...

Laravel macOS Encountered an unexpected character in the input: '

After installing Vagrant on my macOS with the Parallels provider, I initiated a new project using the command laravel new blog. Initially, everything worked fine when I opened the site. However, I encountered issues when trying to add authentication with ...

Send data from an AJAX request to a Laravel controller

Here is the code for my ajax request where I am trying to pass values to a controller in Laravel. var deviceid="<?php echo $id; ?>"; var day="<?php echo $day; ?>"; $.ajax({ 'async': false, 'global': false, url ...

What is a more efficient method for generating HTML code using PHP variables?

My online store showcases a variety of products, each housed in a div with the id content block. The link, image, background, description, and price for each product are all retrieved from a mySQL table. Initially, I planned to store the HTML code below as ...