我在单击时用于图像缩略图的以下代码通过从数据库中获取它的“ID”来执行。
echo '<a class="thumbnail" href="view.php?id='.$row['id'] .'"">';
下面的代码实际上处理通过上述代码传递的 GET 变量。
<?php
require '../header.php';
if (isset($_GET['id']))
{
require '../../functions/function_db.php';
$id =mysql_real_escape_string (htmlentities($_GET['id']));
$sql = "SELECT * FROM `site_products` WHERE `id` = $id LIMIT 1";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
{
$product_name = $row['product_name'];
$price = $row['final_price'];
$desc = $row['short_description'];
}
}
?>
尽管使用了 mysql_real_escape_string,但在以下情况下,URL 仍会成为 SQL 注入漏洞。
http://localhost/cart/pages/men/view.php?id=1'
http://localhost/cart/pages/men/view.php?id=1 orderby 1
并且网页给出了以下mysql错误。
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given
这个怎么解决???