+ -
当前位置:首页 → 问答吧 → php在URL中传递中文参数,插入到mysql乱码问题

php在URL中传递中文参数,插入到mysql乱码问题

时间:2011-10-09

来源:互联网

我需要在url中直接带sql语句,插入到数据库,
http://localhost/insert.php?s=insert+into+members+(uid,username)+values+(null,'蓝色')

这样插入的是乱码,中文变成了   %C0%B6%C9%AB   ,英文和数字一切正常。请问如何解决,谢谢

<?php
include("conn.php");
       $s=urlencode($_GET['s']);
       $s = str_replace('+','%20',$s);
       $s = str_replace('%2C',',',$s);
       $s = str_replace('%27','\'',$s);
       $s = str_replace('%28','(',$s);
       $s = str_replace('%29',')',$s);
       $s = str_replace('%20',' ',$s);
       $s = str_replace('%5C','',$s);
    $SQL="$s";
  $query=mysql_query($SQL);
  $err=mysql_error();
if($err){   
    echo "error:".mysql_error();   
}else{
    echo "success";
}
mysql_close($conn);
?>

作者: 85559444   发布时间: 2011-10-09

数据库与PHP编码不一致?

作者: 无题   发布时间: 2011-10-09