Php+ajax the encoding problem that is encountered when validating a user name
I ran into this problem when I was testing the code.
The code is as follows:
index.php
;
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 "User name already exists";
}else
{
echo "can be used";
}
}
?>
I tested both in the local environment and in the BAE Environment, respectively.
Has appeared the Chinese character can not be normal transmission phenomenon, the database already has "thousand hands" this user, but still prompt can use this user, seemingly is the problem of coding.
, ask the Expert answer ~ PHP Ajax MySQL Test
Share to:
------Solution--------------------
F=encodeuri (f); Just forget to assign value! Give it a try!
------Solution--------------------
It is possible that the database encoding problem is:
Show variables like ' char% '
If you're not mistaken, it's GBK.