Php + json user registration returns json data-PHP source code

Source: Internet
Author: User
The following code is a simple php + json user registration and return json data, because flash and json data exchange are often used during flash interaction, php is used to return data in real time and the code below the json output is a simple php + json user registration to return json data, because flash and json data exchange is often used during flash interaction, we use php to return and output json data in real time.

Script ec (2); script

Require_once ("../Inc/Conn. php ");
Require_once ("../Inc/function. php ");
/*
Receiving flash post Data
Date "2009.04.24
*/


$ User_Name = Get_value ('user _ name', 1 );
$ User_Pass = Get_value ('user _ pass', 1 );
$ Puser_Pass = Get_value ('puser _ pass', 1 );
$ User_Mail = Get_value ('user _ mail', 1 );
$ User_Baby_Sex = Get_value ('user _ Baby_Sex ', 1 );
$ Year = Get_value ('Year', 1 );
$ Month = Get_value ('month', 1 );
$ Day = Get_value ('day', 1 );
$ User_Prov = Get_value ('user _ prov', 1 );
$ User_City = Get_value ('user _ city', 1 );
$ User_rname = Get_value ('user _ rname', 1 );
$ User_Zip = Get_value ('user _ zip', 1 );
$ User_Hand = Get_value ('user _ hand', 1 );
$ User_YesNo = Get_value ('user _ yesno', 1 );
$ User_Address = Get_value ('user _ address', 1 );

If (empty ($ User_Name) | strlen ($ User_name)> 8 ){

ShowMsg ("{" result ":" false "}");

} Elseif (empty ($ User_Pass) | ($ User_Pass! = $ Puser_Pass )){

ShowMsg ("{" result ":" false "}");

} Elseif (! @ Preg_match ("/w + ([-+.] w +) * @ w + ([-.] w + )*. w + ([-.] w +) */", $ User_Mail) | strlen ($ User_Mail) <6 ){

ShowMsg ("{" result ":" false "}");

} Elseif (empty ($ User_Prov) | empty ($ User_City )){

ShowMsg ("{" result ":" false "}");

} Elseif (! Empty ($ User_rname )){

If (strlen ($ User_rname)> 6 ){

ShowMsg ("{" result ":" false "}");

}
}
If (! Empty ($ User_Address )){

If (strlen ($ User_Address)> 100 ){

ShowMsg ("{" result ":" false "}");

}

}

If (! Empty ($ User_Zip )){

If (! Strlen ($ User_Zip) = 6 |! Is_numeric ($ User_Zip )){

ShowMsg ("{" result ":" false "}");
}

}
If (is_numeric ($ User_Hand )){

If (! @ Preg_match ("/d {11}/", $ User_Hand )){

ShowMsg ("{" result ":" false "}");

}
}

$ User_Baby_Birth = @ iconv ('utf-8', 'gb2312', "$ year-$ month-$ day ");

$ Sheng = @ iconv ('utf-8', 'gb2312', $ User_Prov. $ User_City );


$ SQL = "Insert into tablename (User_Name, User_Pass, User_Mail, User_Baby_Sex, User_Baby_Birth, sheng, User_Zip, User_Address ,";

$ SQL. = "User_Hand, User_YesNo, User_rname) values ('$ User_Name', '$ User_Pass', '$ User_Mail', '$ User_Baby_Sex', '$ User_Baby_Birth ',";

$ SQL. = "'$ sheng', '$ User_Zip', '$ User_Address', '$ User_Hand', '$ User_YesNo', '$ User_rname ')";

$ SqlUser = "select User_Name from tablename where User_Name = '$ User_Name '";

$ Result = mysql_query ($ sqlUser) or die (mysql_error (). $ sqlUser );

If (mysql_num_rows ($ result )){

ShowMsg ("{" result ":" false "}");

} Else {

If (mysql_query ($ SQL )){


$ OutPut = "{
"Id": ". mysql_insert_id ().", n
"User_Name": "$ User_Name", n
"User_Mail": "$ User_Mail", n
"User_Baby_Sex": "$ User_Baby_Sex", n
"User_Baby_Birth": "$ User_Baby_Birth", n
"Sheng": "$ sheng", n
"User_Zip": "$ User_Zip", n
"User_Address": "$ User_Address", n
"User_Hand": "$ User_Hand", n
"User_YesNo": "$ User_YesNo", n
"User_rname": "$ User_rname", n
"Result": "true"
}";

ShowMsg ($ outPut );


} Else {

ShowMsg ("{" result ":" false "}");

}

}


?>

Site original reprinted Note: http://www.111cn.net/phper/php.html

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.