Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9156397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:46:05+00:00 2026-06-17T12:46:05+00:00

I’m having a slight issue with prepared statements for PHP and MySQLi . My

  • 0

I’m having a slight issue with prepared statements for PHP and MySQLi. My code takes POST data, prepares a statement and then binds the POST data to the query. After this it executes, seemingly without error, but the statement clearly doesn’t ever get executed correctly since no database changes occur.

A quick overview of my problem:

  1. I’m using MySQLi and prepared statements.
  2. I’ve updated some previous PHP/MySQLi code that was not using prepared statements.
  3. Since updating, a problem has occured with $query->execute().

Code:

if($query = $this->mysqli->prepare("UPDATE article SET copy = ?, title = ?, alias = ?, description = ?, category = ?, category_id = ?, author = ?, permission = ?, mode = ?, comments = ?, revised = ?, frequency = ?, priority = ? WHERE id = ?"))
{
    if
    (
        $query->bind_param
        (
            "sssssdsssssssd", 
            $_POST['edit_article'], 
            $_POST['edit_title'], 
            $_POST['edit_alias'], 
            $_POST['edit_description'], 
            $_POST['edit_category'],
            $result['id'],
            $_POST['edit_author'], 
            $_POST['edit_permission'], 
            $_POST['edit_mode'], 
            $_POST['edit_comments'], 
            $date_time, 
            $_POST['edit_frequency'], 
            $_POST['edit_priority'], 
            $id
        )
    )
    {                   
        if($query->execute())
        {
            echo $this->mysqli->error; // does nothing.

            // These statements print to the screen successfully with the correct values.
            echo $_POST['edit_frequency'] . "<br />";
            echo $_POST['edit_priority'] . "<br />";
            //$_SESSION['article_edited'] = true;
            // die;
            //exit(header("Location: " . __MANAGER__ . $_POST['edit_alias']));
        }
        else
        {
            $_SESSION['article_edited'] = false;

            exit(header("Location: " . __MANAGER__ . $_POST['edit_alias']));
        }
    }
}
else
{
    $_SESSION['article_edited'] = false;

    exit(header("Location: " . __MANAGER__ . $_POST['edit_alias']));
}

Could anybody perhaps explain a better way to debug this code? It makes no sense to me since I check whether the execute() function works with if($query->execute()) and it’s successful. Assuming of course the problem does not lie with the execute function, but elsewhere. The problem can’t be the POST data since it validates fine with:

if
(
    $_POST['foo'] && isset($_POST['foo']) &&
    $_POST['bar'] && isset($_POST['bar'])
)
{
    // Statements.
}

I am clueless.

EDIT

I would like to note I echo the values of 2 particluar POST vars since those were the ones I added in when updating the code. It has since stopped working. Also note I have used print_r($_POST) and all POST vars are set and contain values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:46:06+00:00Added an answer on June 17, 2026 at 12:46 pm

    Problem has been solved.

    The error was, as expected, not caused by a malfunction or faulty logic, rather an unchanged variable $id, that should have been converted to $_POST['id']. For those that read this in the future, it may be worthwhile noting that Amit Agrawal’s reply is actually an important one.

    Please bear in mind that the SQL statement was not in error, it just so happened that no rows were affected since the variable $id was not set or initialised. Therefore, the appropriate course of action would be something along the lines of:

    if($query->execute())
    {
        if($this->mysqli->affected_rows == 0)
        {
            // Appropriate action (such as raising an error), e.g.,
            die("No rows were affected");
        }
        else
        {
            // Appropriate action.
        }
    }
    else
    {
        die("Query could not be executed.");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.