进行转议,试试一、$_GET['category']=addslashes($_GET['category']") $queryitems = "SELECT itm.* FROM wutao.item as itm, wutao.category as cate where cate.itemid=itm.itemid and cate.category = '".$_GET['category']."'"; 二、将'替换为\' $_GET['category']=str_replace ( "'", "\'",$_GET['category'] )$queryitems = "SELECT itm.* FROM wutao.item as itm, wutao.category as cate where cate.itemid=itm.itemid and cate.category = '".$_GET['category']."'"; 试一下
<?php
function insertMysql($str) { if(get_magic_quotes_gpc())return $str;
推荐写法:$queryitems = sprintf( "SELECT itm.* FROM wutao.item as itm, wutao.category as cate where cate.itemid=itm.itemid and cate.category='%s'", addslashes($_GET['category']) ); 用sprintf()格式化查询语句,用addslashes()对特殊字符转义.
$queryitems = "SELECT itm.* FROM wutao.item as itm, wutao.category as cate where cate.itemid=itm.itemid and cate.category = '".addslashes($_GET['category'])."'"; 试试
例子:
<?php
$item = "Zak's and Derick's Laptop";
$escaped_item = mysql_real_escape_string($item);
printf ("Escaped string: %s\n", $escaped_item);
?> 以上例子将产生如下输出:
Escaped string: Zak\'s and Derick\'s Laptop
$queryitems = "SELECT itm.* FROM wutao.item as itm, wutao.category as cate where cate.itemid=itm.itemid and cate.category = '".$_GET['category']."'";
二、将'替换为\'
$_GET['category']=str_replace ( "'", "\'",$_GET['category'] )$queryitems = "SELECT itm.* FROM wutao.item as itm, wutao.category as cate where cate.itemid=itm.itemid and cate.category = '".$_GET['category']."'";
试一下
<?php
function insertMysql($str)
{
if(get_magic_quotes_gpc())return $str;
//'--这里添加对应的转义规则
$arr =array('\\', '\'');
$patt=array('\\\\','\\\'');
return str_replace($arr,$patt,$str);
} $str = insertMysql($str);//'-------4
$_GET = array_map('insertMysql', $_GET);
$_POST = array_map('insertMysql', $_POST);
$_SERVER = array_map('insertMysql', $_SERVER);
//'-------5
$_GET = array_walk_recursive($_GET, 'insertMysql')
$_POST = array_walk_recursive($_POST , 'insertMysql');
$_SERVER = array_walk_recursive($_SERVER , 'insertMysql');
?>http://blog.tonyang.com/?action=show&id=90
sql server ''[align=center]==== 思想重于技巧 ====
[/align]
只有过滤掉
可以参考:http://www.cndw.com/tech/asp/20000624296.asp
"SELECT itm.* FROM wutao.item as itm, wutao.category as cate where cate.itemid=itm.itemid and cate.category='%s'",
addslashes($_GET['category'])
);
用sprintf()格式化查询语句,用addslashes()对特殊字符转义.
if(!$magic_quotes_gpc)
{
$_POST = addslashes($_POST);
$_GET = addslashes($_GET);
}phpcms的作法..把post与get的数组自动转义.