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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:17:07+00:00 2026-06-18T15:17:07+00:00

I am new to PDO and prepared statements and I am having trouble binding

  • 0

I am new to PDO and prepared statements and I am having trouble binding multiple values to my query. I have no problem if it is just one while making a SELECT, for example:

SELECT foo FROM table WHERE id=:something // no problem

But multiple, and trying to INSERT I am getting stuck:

Insert INTO mytable (field1, field2) VALUES (:value1, :value2) // No bueno 

Have tried a few different ways and read other posts on here but no luck. Below is an example of what I am having trouble with:

$insertSQL = $db->prepare("INSERT INTO voting_poll (ipaddress, choice) 
    VALUES (':ipaddress', :value)");
    $insertSQL->bindParam(':ipaddress', getenv('REMOTE_ADDR'), PDO::PARAM_STR);
    $insertSQL->bindParam(':value', $_POST['radio'], PDO::PARAM_STR);
    $insertSQL->execute();

I am getting the following error: Invalid parameter number: number of bound variables does not match number of tokens

  • 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-18T15:17:08+00:00Added an answer on June 18, 2026 at 3:17 pm
    1. You don’t put quotes around params. Remove the quotes around :ipaddress in your query.

    2. bindParam() must be used with a variable as it binds the parameter to the variable reference. If you want to use a value (for example, the return value from a function like getenv()), use bindValue() instead.

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

Sidebar

Related Questions

I'm having trouble finding good documentation on pdo update prepared statements and even more
I'm having trouble converting this now() + INTERVAL INSERT statement to a PDO prepared
I am having a bit of a problem binding a value with PDO and
I'm new to PHP and PDO, and I try to use prepared statements here.
I am extremely new to PHP. I'd like to use prepared PDO statements, but
I'm trying to switch from mySql statements to PDO prepared statements, but I'm having
I am still new to PDO and am having trouble getting the update statement
Using PHP v. 5.2.14 and PDO-MySQL extension. I am new to prepared statements. Need
I'm having a strange problem with php PDO and mysql. I have the following
while using the following constructor $this->pdo = new PDO ($this->source, $this->username, $this->password); if I

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.