Encoding problems encountered during user name authentication using php + Ajax

Source: Internet
Author: User
I encountered the encoding problem when I used php + Ajax to verify the user name. I encountered this problem while testing the code. The code is as follows: index. php & lt; script & nbsp; type = "text/javascript" & nbsp; src = "ajax. js "& gt; & lt;/script & gt; & nbsp; & l php + Ajax encoding problems encountered when verifying the user name
I encountered this problem when testing the code.
The code is as follows:
Index. php

《script》
  
;
Ajax. js


var xmlHttp;
function S_xmlhttprequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}

function funphp100(name) {

   var f=document.myform.user.value;
S_xmlhttprequest();
xmlHttp.open("GET","for.php?id="+f,true);
xmlHttp.onreadystatechange = byphp;
xmlHttp.send(null);
}

function byphp() {

  if(xmlHttp.readyState == 1) {
 document.getElementById('php100').innerHTML = "";
}

    if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200) {
          var byphp100 =  xmlHttp.responseText;
          document.getElementById('php100').innerHTML = byphp100;
}
}


}

For. php

If (@ $ _ GET [id]) {
Sleep (1 );
$ Conn = mysql_connect ('localhost', 'root ','');
Mysql_select_db ('test', $ conn );

Echo $ SQL = "SELECT * FROM 'user' where 'user' = '$ _ GET [id]'";
$ Q = mysql_query ($ SQL );

If (is_array (mysql_fetch_row ($ q ))){
Echo "the user name already exists ";
} Else
{
Echo "available ";
}
}
?>

I tested both the local environment and the BAE environment.
There is a phenomenon that Chinese characters cannot be transmitted normally. the database already has a "Thousand Hands" user, but it still prompts you to use this user, which seems to be a problem of encoding.
, Ask someone else to answer ~ PHP Ajax MySQL test: script?... 'Data-pics = ''>
------ Solution --------------------
F = encodeURI (f); forgot to assign a value! Try it!
------ Solution --------------------
It is likely that the problem of database encoding is:
show variables like 'char%'

I guess it's GBK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.