This question already has an answer here:
I have the following php function and have checked it over countless times.
I have looked at about 30 different questions abouts the HY903 error code. However, none of them seem to apply.
I have checked the number of columns, with the number of placeholders, I have checked that the spelling is consistent. I have even enclosed values that could be null in if(!is_null){} but nothing seems to shift this error. I have to be missing something small, but I can't for the life of me find out what it is.
function add_page($title, $linkStub, $content,$gitTitle,$buttonLabel,$buttonLink,$buttonText,$buttonTarget)
{
$sql = "INSERT INTO `pages`(
`pageId`,
`title`,
`linkStub`,
`content`,
`gitTitle`,
`buttonLabel`,
`buttonLink`,
`buttonText`,
`buttonTarget`
)
VALUES (
NULL ,
:title ,
:linkStub ,
:content ,
:gitTitle ,
:buttonLabel ,
:buttonLink,
:buttonText,
:buttonTarget
)";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':title', $title, PDO::PARAM_STR, 100);
$stmt->bindParam(':linkStub', $linkStub, PDO::PARAM_STR, 150);
$stmt->bindParam(':content', $content, PDO::PARAM_STR);
if(!is_null($gitTitle))
{
$stmt->bindParam(':gitTitle', $gitTitle, PDO::PARAM_STR, 150);
}
if(!is_null($buttonLink))
{
$stmt->bindParam(':buttonLabel', $buttonLabel, PDO::PARAM_STR, 150);
$stmt->bindParam(':buttonLink', $buttonLink, PDO::PARAM_STR, 150);
$stmt->bindParam(':buttonText', $buttonText, PDO::PARAM_STR, 100);
$stmt->bindParam(':buttonTarget', $buttonTarget, PDO::PARAM_INT, 2);
}
$bool = $stmt->execute();
print_pre($stmt->errorInfo()); //Uncomment for error reporting
return $bool;
}
EDIT:
This question is not a duplicate of the ones you marked these issues there were incorrect amount of bindings, this is dealing with NULL values which Robbie Averill kindly pointed out.
</div>