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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:59:58+00:00 2026-05-27T09:59:58+00:00

I am having some trouble with an insert query in php, for some reason

  • 0

I am having some trouble with an insert query in php, for some reason it fails. I have echoed out the variables and they do equal something.

$query = "INSERT into thrives (n_emp, comment, g_emp) VALUES (':n_emp', ':comment', ':g_emp')";
$db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$statement = $db -> prepare($query);
$statement -> bindValue(':n_emp', $name, PDO::PARAM_INT);
$statement -> bindValue(':comment', $comment, PDO::PARAM_STR);
$statement -> bindValue(':g_emp', $_SESSION['emplid'], PDO::PARAM_INT);
$result = $statement -> execute();
$statement -> closecursor();

I pass the output to a alertbox and this is what i get.

Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in /Applications/XAMPP/xamppfiles/htdocs/jen/maintabs/submit.php:33
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/jen/maintabs/submit.php(33): PDOStatement->execute()
#1 {main}
  thrown in /Applications/XAMPP/xamppfiles/htdocs/jen/maintabs/submit.php on line 33

Anyone see where i’m going wrong?

UPDATE 1

I added the ‘ in front of :comment, this is the new error message

Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`login`.`thrives`, CONSTRAINT `thrives_ibfk_1` FOREIGN KEY (`n_emp`) REFERENCES `employees` (`ID`))' in /Applications/XAMPP/xamppfiles/htdocs/jen/maintabs/submit.php:33
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/jen/maintabs/submit.php(33): PDOStatement->execute()
#1 {main}
  thrown in <b>/Applications/XAMPP/xamppfiles/htdocs/jen/maintabs/submit.php</b> on line <b>33</b><br />
  • 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-27T09:59:59+00:00Added an answer on May 27, 2026 at 9:59 am

    Remove the quotes from your bound parameters. It should read INSERT into thrives (n_emp, comment, g_emp) VALUES (:n_emp, :comment, :g_emp). The single quotes make it a literal string otherwise.

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

Sidebar

Related Questions

I'm having some trouble getting NH to persist my object graph. I have (something
Im having some trouble writing a getstring function, this is what I have so
I am having some trouble with the Google Maps API . I have an
having a bit of trouble adding some data to a database. I have the
I am having some trouble with using h:selectOneRadio . I have a list of
I'm having some trouble with navigation when using Facelets. I have my master template
I'm having some trouble with this program. I think I have it almost right,
I'm having some trouble with a SQL transaction using PHP and mySQL. Here is
This is probably stupid simple, but for some reason I'm having trouble getting it
Im having some trouble getting on with my first codeigniter project, and i have

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.