作为工作的一部分,我想使用表单更新数据库。由于数据库很大并且被很多用户使用,我希望这种操作至少是安全的,以便更安全。
HTML 脚本:
<form action="http://localhost/modifier_infos_signaletique.php" method=POST >
<div class="id_sign">
<h5>Id "Signalétique" :</h5>
<input type="text" name="id_sign" id="id_sign"/><br>
</div>
<h5>Infos "Signalétique" : </h5>
<input class="comment" type="text" id="maj_infos" name="maj_infos" required maxlength='140'/><br>
<input type="submit" value="Submit" />
</form>
脚本:
<?php
$user = 'xxxx';
$pass = 'xxxx';
try{
$dbconn = new PDO('pgsql:host=localhost;port=5432;dbname=xxxx',$user, $pass);
$dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$maj = $_POST['maj_infos'];
$id = $_POST['id_sign'];
$query = $dbconn->prepare("UPDATE signaletique SET infos = ':infos' WHERE id = ':id'");
$query->bindParam(':infos', $maj, PDO::PARAM_STR);
$query->bindParam(':id', $id, PDO::PARAM_INT);
$query->execute();
echo 'Données mises à jour';
}
catch(PDOException $e){
echo "Erreur : " . $e->getMessage();
}
?>
但是,当我使用此脚本时,会出现此错误:
**错误:SQLSTATE[HY093]:无效参数号::infos **
该错误是由于用于 bindParam 函数的参数引起的。但是,我在我的 PostgreSQL 数据库的属性中有“字符变化”中的信息。我试图将此参数更改为“文本”,但错误仍然存在。
请原谅我提出这个问题,但我是 PHP 的新手,而且我的 SQL 技能很薄弱,因为我经常使用 pgAdmin 及其工具来构建我的数据库并与之交互。
这是我的数据库的屏幕截图:
信息参数在屏幕截图的“文本”中,但基本此属性在“字符变化”(140) 中。
感谢您的帮助。
POPMUISE