Php+ajax problems encountered when authenticating user names

Source: Internet
Author: User
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.
  • 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.