PHP + MYSQL: Invalid parameter number: number of bound variables does not match...
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
PHP + MYSQL: Invalid parameter number: number of bound variables does not match...
Hello Everybody,
I am attempting to Insert some data into my mySQL table but it's not working; instead it throws the following error:
Quote:
Database Error: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
My table was made from the following script:
Code:
CREATE TABLE users (
userID INT NOT NULL AUTO_INCREMENT,
f_name VARCHAR(30) NOT NULL,
l_name VARCHAR(30) NOT NULL,
m_name VARCHAR(30) DEFAULT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(60) NOT NULL,
bday CHAR(10),
city varchar(200),
zipCode INT,
relationship varchar(30) DEFAULT NULL,
profilePic varchar(255) NOT NULL,
sex char(1) NOT NULL,
valid TINYINT(1) NOT NULL DEFAULT 0,
confirm varchar(12) NOT NULL,
PRIMARY KEY (userID),
UNIQUE INDEX email (email)
);
And the code that I am attempting to run in order to insert the values is:
PHP Code:
require_once 'database_connect.php';
//Functions that will change data on the Users tables.
//Initial user add; Only used after the user registers.
function add_user($f_name, $l_name, $email, $password, $bday, $zipCode ,$sex, $confirm, $m_name)
{
global $db;
//Prepare data to be inserted
$password = md5($email . $password_1);
//Hard Coded in For testing.. Normally I would leave these Null for the moment.
$statement->bindValue(':city', $city);
$statement->bindValue(':relationship', $relationship);
$statement->bindValue(':valid', $valid);
I have been wrestling with this problem for a good 4.5 hours and I haven't figured it out yet.
Does anybody know what the problem is, or can at least point me in the right direction?
I would start by doing what the error complains about. You have 14 fields in your table but you are only binding 13 of them to values. Just because you have a field that is auto incremented, does not mean you can omit a value for it in your insert statement. A simple zero will suffice.
Hmm, I tried adding all the values, but I still got the same error. Then I found that I had accidentally used the wrong variable to bind the values, so just in case, I tried inserting constant data into the database, but it's still not working- I get the same error as before.
Any ideas?
PHP Code:
require_once 'database_connect.php';
//Functions that will change data on the Users tables.
//Initial user add; Only used after the user registers.
function add_user($f_name, $l_name, $email, $password, $bday, $zipCode ,$sex, $confirm, $m_name)
{
global $db;
//Prepare data to be inserted
// $password = md5($email . $password_1);
//Hard Coded in For testing.. Normally I would leave these Null for the moment.
$statement->bindValue(':city', $city);
$statement->bindValue(':relationship', $relationship);
$statement->bindValue(':valid', $valid);
$statement->bindValue(':userID', $userID);
Thank you,
That was one of the problems. The other one that was causing an issue was the fact that I forgot to add a colon to my values, so there was no binding for the confirm parameter.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.