I've spent a good few hours trying to find the answer to this, even though it seems simple. I know that this error is usually a result of a quote being wrong, but this is the first time I've used PDO and I've tried various combinations of quotes, using BindParam instead of executing with an array, etc. Either this issue is a bit more complicated than that or I'm blind from staring at the code for too long. :)
<?php
$name = $_POST['name'];
$table = $_POST['type'];
$largepath = $_POST['largeimagepath'];
$smallpath = $_POST['smallimagepath'];
$name = htmlentities($name);
$table = htmlentities($table);
$largepath = htmlentities($largepath);
$smallpath = htmlentities($smallpath);
$connection = new PDO('mysql:host=xxx;dbname=xxx',xxx,xxx);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO :table (name,imagepath,thumbimagepath) VALUES (:name,:image,:thumb)";
$query = $connection->prepare($sql);
$query->execute(array(":table"=>$table,
":name"=>$name,
":image"=>$largepath,
":thumb"=>$smallpath));
if($query->rowCount()) {
echo "Inserted correctly";
} else {
echo "Failure inserting";
}
?>
The error shows up on the line "$query->execute(array":table"=>$table,". When I had that changed to bindparams before the execute though, the error showed up only on the second bindparam, although the two were identical. Very strange. Am I missing something really obvious here?