PHP 未更新 table 中的数据 (bindParam)

PHP is not updating the data in table (bindParam)

下面是我试图通过 POST 请求 运行 的附加查询。

我已经检查(回显)提交时的值,我得到的是最新值,这意味着表单方面没有问题。我没有收到任何错误。查询后的回显也有效,但记录未在 table 中更新。我在查询中仔细检查了拼写错误,这对我来说似乎没问题。 下面是查询(我在这里替换了table名字)

$sql="UPDATE table_name SET name = :name, email = :email, category = :category, mobile = :mobileno, description = :description, website = :website, address = :address, city = :city, state = :state, zip = :zip, image = :image  WHERE  id = :editid";
$query = $dbh->prepare($sql);
$query-> bindParam(':name', $name, PDO::PARAM_STR);
$query-> bindParam(':email', $email, PDO::PARAM_STR);
$query-> bindParam(':category', $category, PDO::PARAM_STR);
$query-> bindParam(':mobileno', $mobileno, PDO::PARAM_STR);
$query-> bindParam(':description', $description, PDO::PARAM_STR);
$query-> bindParam(':website', $website, PDO::PARAM_STR);
$query-> bindParam(':address', $address, PDO::PARAM_STR);
$query-> bindParam(':city', $city, PDO::PARAM_STR);
$query-> bindParam(':state', $state, PDO::PARAM_STR);
$query-> bindParam(':zip', $zip, PDO::PARAM_STR);
$query-> bindParam(':image', $image, PDO::PARAM_STR);
$query-> bindParam(':editid', $editid, PDO::PARAM_STR);
$query->execute();

在 MySQL 中有一些保留关键字,如果不转义查询中的字段,您将无法使用这些关键字。完整列表可以在 MySQL-documentation.

中找到

尝试下面的查询并检查查询现在是否正确处理。

$sql="UPDATE `table_name` SET `name` = :name, `email` = :email, `category` = :category, `mobile` = :mobileno, `description` = :description, `website` = :website, `address` = :address, `city` = :city, `state` = :state, `zip` = :zip, `image` = :image  WHERE `id` = :editid";
$query = $dbh->prepare($sql);
$query-> bindParam(':name', $name, PDO::PARAM_STR);
$query-> bindParam(':email', $email, PDO::PARAM_STR);
$query-> bindParam(':category', $category, PDO::PARAM_STR);
$query-> bindParam(':mobileno', $mobileno, PDO::PARAM_STR);
$query-> bindParam(':description', $description, PDO::PARAM_STR);
$query-> bindParam(':website', $website, PDO::PARAM_STR);
$query-> bindParam(':address', $address, PDO::PARAM_STR);
$query-> bindParam(':city', $city, PDO::PARAM_STR);
$query-> bindParam(':state', $state, PDO::PARAM_STR);
$query-> bindParam(':zip', $zip, PDO::PARAM_STR);
$query-> bindParam(':image', $image, PDO::PARAM_STR);
$query-> bindParam(':editid', $editid, PDO::PARAM_STR);
$query->execute();

编辑: 如果所有输入都是字符串,并且 table 字段是字符串,那么这应该可行。虽然我怀疑正在使用的字段不都是字符串......在那种情况下绑定会失败并且查询不会处理。 如果您提供有关您尝试更新的 table 和一些示例数据的更多信息,我将更新此答案。