JensV
JensV

Reputation: 4544

Issue with php/mysql prepared insert statement

I might just be too dumb to see it but here is my issue:

Code:

$stmt = $mysql->prepare("INSERT INTO projects_files (mid,filename,type) VALUES ('?','?','?')");
$stmt->bind_param('isi',$this->id,$File->filename,$File->type);

Error:

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

I have checked that all vars are assigned and have a value and the datatypes are all right.

Thanks in advance for help

Upvotes: 0

Views: 89

Answers (2)

Ranjith
Ranjith

Reputation: 2819

Remove the bindparam single quotes(') around the question mark(?)

$stmt = $mysql->prepare("INSERT INTO 
                     projects_files (mid,filename,type) 
                     VALUES (?,?,?)");
$stmt->bind_param('isi',$this->id,$File->filename,$File->type);

Upvotes: 1

Cully
Cully

Reputation: 6965

Don't put the question marks in quotes. The database will quote everything appropriately.

$stmt = $mysql->prepare("INSERT INTO projects_files (mid,filename,type) VALUES (?,?,?)");
$stmt->bind_param('isi',$this->id,$File->filename,$File->type);

Upvotes: 1

Related Questions