Warning: PDOStatement::execute(): SQLSTATE[HY093]:


Warning: PDOStatement::execute(): SQLSTATE[HY093]:

我正试图开始掌握PHP和PDO。当我现在开始的时候,我听说PDO更有益,这就是为什么我不使用更流行的mysqli。

我在使用PDO将数据插入数据库时遇到问题。我想尝试使用准备好的语句来最大限度地减少sql注入。我尝试了很多方法,但总是碰壁。

请给我一些建议。

这是错误消息。

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:'wamp'www'test-search'insert_property.php on line 61

这是相关的php代码。

// Insert Property
// Include db 
include 'db_connect_pdo.php';
include 'defines.php';
try {
// create SQL
$sql = "INSERT INTO property (pid, title, intro_en, description_en, bedrooms,
bathrooms, address, city, country, stype, ptype, price)
VALUES(:pid, :title, :intro_en, :description_en, :bedrooms, :bathrooms, :address,
:city, :country, :stype, :ptype, :price)";
// prepare the statement
$stmt = $conn->prepare($sql);

// bind the parameters and execute the statement
$stmt->bindValue(':pid', $pid);
$stmt->bindValue(':title', $title);
$stmt->bindValue(':intro_en', $intro_en);
$stmt->bindValue(':description_', $description_en);
$stmt->bindValue(':bedrooms', $bedrooms);
$stmt->bindValue(':bathrooms', $bathrooms);
$stmt->bindValue(':address', $address);
$stmt->bindValue(':city', $city);
$stmt->bindValue(':country', $country);
$stmt->bindValue(':stype', $stype);
$stmt->bindValue(':ptype', $ptype);
$stmt->bindValue(':price', $price);

// execute the statement
$stmt->execute();
} 
catch (Exception $e) 
{ 
echo $e->getMessage(); 
} 
$conn = null;
?>
</blockquote></code>

不确定哪里出了问题,任何建议都将不胜感激。

您的错误是这一行:

$stmt->bindValue(':description_', $description_en);

应为:

$stmt->bindValue(':description_en', $description_en);