Issue with php/mysql prepared insert statement

968

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

46

Answer

Solution:

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);
403

Answer

Solution:

Remove thebindparam 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);

People are also looking for solutions to the problem: php - Uploading Wordpress site

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.