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 7534619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:04:24+00:00 2026-05-30T06:04:24+00:00

Firstly, sorry if my title doesn’t quite explain the situation, I had problems thinking

  • 0

Firstly, sorry if my title doesn’t quite explain the situation, I had problems thinking of a good one.
I’m trying to take all the input from a form and put them into a database. I’m not 100% sure at this point if this is possible, but I thought I’d post it to make sure. The code is commented, but I get

INSERT INTO items (title, description, category, size) VALUES (?, ?, ?, ?)
'ssss', $fields[0][1], $fields[1][1], $fields[2][1], $fields[3][1]
Warning: Wrong parameter count for mysqli_stmt::bind_param()

I’m guessing this is because I’m passing the variable, and not its value. But even if I did pass its value, whether or not it’s good code is questionable to me.

        // $fields[x][0] is title of x, $fields[x][1] is value of x
        $statement = 'INSERT INTO items (';
        // Add all the field names
        for ($i = 0; $i < count($fields) - 1; $i++) {
            $statement .= $fields[$i][0] . ', ';
        }
        $statement = $statement . $fields[count($fields) - 1][0] . ') VALUES (';
        // Add '?' for every field
        for ($i = 0; $i < count($fields) - 1; $i++) {
            $statement .= '?, ';
        }
        $statement = $statement . '?)';
        echo $statement . '<br />';
        // Add all the value types to the statement
        $params = '\'';
        for ($i = 0; $i < count($fields); $i++) {
            if (gettype($fields[$i][1]) == 'integer') {
                $params .= 'i';
            } else {
                $params .= 's';
            }
        }
        $params .= '\', ';
        // Put the values into the statement
        for ($i = 0; $i < count($fields) - 1; $i++) {
            $params .= '$fields[' . $i . '][1], ';
        }
        $i = count($fields) - 1;
        $params .= '$fields[' . $i . '][1]';
        echo $params;
        // Put it all in the database
        $db = mysqlConnect();
        $stmt = $db->stmt_init();
        $stmt->prepare($statement);
        $stmt->bind_param($params);
        $stmt->close();
        $db->close();
  • 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-05-30T06:04:26+00:00Added an answer on May 30, 2026 at 6:04 am

    From PHP manual for bind_param: (http://php.net/manual/en/mysqli-stmt.bind-param.php)

    bool mysqli_stmt::bind_param ( string $types , mixed &$var1 [, mixed &$... ] )
    

    You are calling

    $stmt->bind_param($params);
    

    So you should have the types in a separate variable, not in $params and call it like this:

    $stmt->bind_param($types,$params);
    

    Keep in mind that this looks a bad idea to me in general. Since the items table has a specific schema, you should probably have a hardcoded query and types variable, and just put the values to params array in the required format.

    You’ll have cleaner code and won’t have to deal with ill-formed fields array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, sorry about the question title, it may not be very descriptive for my
I am sorry if the title is unclear. Allow me to elaborate further. Firstly,
Firstly, thanks for your help. Here's my situation: I'm trying to edit the code
Firstly, I feel sorry about the title, I do not know how to describe
Firstly, i am sorry if the title does not properly describe my problem, but
Firstly sorry for the long piece of code pasted below. This is my first
Firstly, sorry for my English (I'm from China). By reading this article( how to
Firstly I asked sorry if this is a stupid question. but I have a
I'm trying to binarise a picture, firstly of course having it prepared(grayscaling) My method
Greetings, everyone: Firstly, sorry that my Flow description is long winded, but I think

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.