Busy one night finally solved this problem, about U3dunity3d using the HTTP protocol to connect servers and databases to implement a user login function
U3d Code:
usingUnityengine;
usingSystem.Collections;
Public class Submit : Monobehaviour
{
Public string URL = "http://Huang.Me/Login1.PHP";
//ui
Public Uiinput User;
Public Uiinput Password;
IEnumerator OnClick ()
{
Wwwform sum = New Wwwform ();
sum.AddField ("username", User.value);
sum.AddField ("UPass", Password.value);
WWW WW2 = New WWW (URL, sum);
yield return WW2;
Debug.Log (WW2.text);
if (WW2.text == "1") {
Debug.Log ("correct");
} Else {
Debug.Log ("Input Error");
}
}
}
The code is very simple, it should be noted that: when binding the URL address, to see if there is no update address.
PHP Code:
<?php
Get user input over parameters
$username =$_post["username"];
$password =$_post["Password"];
Connecting to a database
$conn =mysql_connect ("127.0.0.1", "Root", "" ");
Open Database
mysql_select_db ("Game");
Execute SQL
$sql = "SELECT * from user where uname= '". $username. "' and upass= '". $password. "';";
$result =mysql_query ($sql);
if ($result >0) {
echo "1";
}else{
echo "0";
}
Close data
Mysql_close ($conn);
?>
In the database is to make the form to save data to take data
This article is from the computer blog, so be sure to keep this source http://5152481.blog.51cto.com/5142481/1607189
Unity3d connecting servers and databases with the HTTP protocol