UPDATE:This is not a duplicate of "Invalid parameter number: parameter was not defined" Inserting data This problem is referring to the Yii framework, and the questioner had used the wrong variable, he stated that the question should possibly be removed as the issue did not lie with PDO in general. This is a different question.
This code for my CMS is designed to update product information that already exists per a product. Currently when I update the info, I return to the same page and get this error and info echoed out for each product attempted to update...
Total: 5, Priority: 1, Label: Clothing, Value: Shirt, Visible: true, ID:34
"UPDATE product_attributes SET priority = :priority, label = :label, value = :value, single_line = :single_line WHERE product_id = :product_id "
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
$id = $_GET['id'];
for($i = 0; $i < $totalProducts; $i++){
if(!empty($_POST)){
try {
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE product_attributes SET priority = :priority,
label = :label,
value = :value,
visible = :visible
WHERE product_id = :product_id";
//Prepare Statement
$query = $pdo->prepare($sql);
$query->bindValue(' :priority ', $_POST['priority' . $i]);
$query->bindValue(' :label ', $_POST['label' . $i]);
$query->bindValue(' :value ', $_POST['value' . $i]);
$query->bindValue(' :visible ', $_POST['visible' . $i]);
$query->bindValue(' :product_id ', $id);
//Execute the query
$query->execute();
// echo a message to say the UPDATE succeeded
echo $query->rowCount() . " records UPDATED successfully";
}
catch(PDOException $e)
{
echo "<br>Priority:" . $_POST['priority' . $i] . "<br>";//currently echoes "1"
echo "<br>Label:" . $_POST['label' . $i] . "<br>";//currently echoes "clothing"
echo "<br>Value:" . $_POST['value' . $i] . "<br>";//currently echoes "shirt"
echo "<br>Visible:" . $_POST['visible' . $i] . "//<br>";//echoes "true"
echo "<br>ID:" . $id . "<br>";//currently echoes "34"
echo '"' . $sql . " \"<br>" . $e->getMessage() . "<br>";
}
}
}
However, I have an equal amount of bound values and SQL fields being updated. I have been searching through other answered questions but none of them resolve my issue. Why is it that it is saying a parameter was not defined?