I'm getting this error message from MySQL DB on PHP/Apache 2:
[text]Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: "Number of variables doesn't match number of parameters in prepared statement"[/text]
And here's my code:
Code: Select all
$sql = "UPDATE
secondhandBooks
SET
`bookTitle` = ?,
`bookAuthor` = ?,
`condition` = ?,
`price` = ?,
`Available` = ?,
`Weight` = ?,
`Publisher` = ?,
`Description` = ?,
`Format` = ?
WHERE
`ItemID` = ? ";
if ( ! $stmt = $db->prepare($sql))
{
$feedback = $stmt->error;
}
else
{
$stmt->bind_param('ssiiiissii', $fTitle, $fAuthor, $fCondition, $fPrice, $fAvailable, $fWeight, $fPublisher, $fDescription, $fFormat, $itemid);
if ( ! $stmt->execute())
{
$feedback = $stmt->error;
}
else
{
$_SESSION['updatefeedback'] = '<p>Item was updated</p>';
$stmt->close();
}
}
Code: Select all
$sql = "INSERT INTO
secondhandBooks
(
`bookTitle`,
`bookAuthor`,
`condition`,
`price`,
`Available`,
`Weight`,
`Publisher`,
`Description`,
`Format`
)
VALUES
( ?, ?, ?, ?, ?, ?, ?, ?, ? )";
if ( ! $stmt = $db->prepare($sql))
{
$feedback = $stmt->error;
}
else
{
$stmt->bind_param('ssiiiissi', $fTitle, $fAuthor, $fCondition, $fPrice, $fAvailable, $fWeight, $fPublisher, $fDescription, $fFormat);
if ( ! $stmt->execute())
{
$feedback = $stmt->error;
}
else
{
$_SESSION['updatefeedback'] = '<p>Item was added</p>';
$stmt->close();
}
}
A very nice gentleman pointed out that 'condition' was a reserved word and so I needed back-ticks around the column names. Adding those fixed my INSERT problem but not my UPDATE problem. Since then the post has gone dead... so here it is fresh and new!
The help from a PHP/SQL guru would be most appreciated at this point.