<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<?php
session_start() ;
include_once("../include/conn.php") ;
$username=trim($_POST["username"]) ;
$userpwd=trim($_POST["userpwd"]) ; $username=iconv("utf-8" , "gb2312//IGNORE" , $username) ;
$userpwd=iconv("utf-8" , "gb2312//IGNORE" , $userpwd) ;
$userpwd=md5($userpwd) ;
//var_dump($userpwd) ;
$sql="select * from rem_table where rem_number='$username' and rem_pwd='$userpwd'" ;
$mysql=mysql_query($sql) or die("Could not query.".mysql_error()) ;
$info=mysql_num_rows($mysql) ;
//var_dump($info) ;
if($info!=0){
$str=mysql_fetch_object($mysql) ;
$_SESSION["rem_number"]=$str->rem_number ;
$_SESSION["rem_name"]=$str->rem_name ;
echo "<script language='javascript'>alert('成功登入!') ;window.location.href='rem_list.php' ;</script>" ;
//header("location:'rem_list.php'") ;
}
else{
echo "<script language='javascript'>alert('输入的用户名或密码不正确!') ;window.location.href='../index.html' ;</script>" ;
}
?>
</body>
</html>
问题:
php中js的alert()弹出乱码,而页面其他部分是正常的
请教

解决方案 »

  1.   

    把alert("");里面的中文字符串转换成utf8的
      

  2.   

    或者 http://zhidao.baidu.com/question/384124461.html
      

  3.   

    楼主session_start() ;前面已经输出那么多内容了没有报错吗?
    楼主你数据库是GB2312的?页面编码是UTF8的?
    看看是不是文件保存为GB2312了,但是网页指定了UTF8导致乱码。
      

  4.   

    在你的php代码段中指定编码:header('content-type:text/html;charset=utf-8;');
    数据库,php代码和页面中的编码最好是统一的。
      

  5.   

    首先各部分的编码一定要统一,如果都统一了,在你的代码中
    else{
    echo "<script language='javascript'>alert('输入的用户名或密码不正确!') ;window.location.href='../index.html' ;</script>" ;
    }
    else里的echo "<script>"之前加header('content-type:text/html;charset=utf-8;');
      

  6.   

    明显是你这个文件的编码不对
    而你的程序写得恰好使你的数据库连接对了建议:
    1 别用iconv,那玩意很容易出毛病
    2 你的所有文件,数据库,都用utf-8保存
      

  7.   

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">(1)
    $userpwd=iconv("utf8" , "gb2312//IGNORE" , $userpwd) ;(2)看好里面是UTF8不是-8
    把文字的格式设置为以UTF-8格式编码(3)