Register Script :-
==================
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Text.RegularExpressions;
public class Register : MonoBehaviour {
public InputField usernameInputField;
public InputField EmailidInputField;
public InputField PasswordInputField;
public string username;
public string emailid;
public string password;
public string ErrorString;
public Text ErrorMsg;
string register_url = "http://www.yourdomain.com/dr/Register1.php";
public Image InternetCheckPanel;
public Image RegisterSuccessfulPanel;
public Text DidnotenterText;
public Image LoginPanel;
public Image RegisterPanel;
public Button Join;
public Text EmailErrorText;
public Text UsernameErrorText;
public Text RegisterCheckText;
public string answer;
void Start () {
InternetCheckPanel.gameObject.SetActive (false);
RegisterSuccessfulPanel.gameObject.SetActive (false);
}
public void JoinButton()
{
string UserEmail = EmailidInputField.text;
string UserEntername = usernameInputField.text;
if ((usernameInputField.text != "") && (EmailidInputField.text != "") && (PasswordInputField.text != ""))
{
if((!IsValidUsername(UserEntername)) && (IsvalidEmailId(UserEmail)))
{
UsernameErrorText.text = "Username should be minimum 8 to 12 characters";
EmailErrorText.text = "";
}
if((IsValidUsername(UserEntername)) && (!IsvalidEmailId(UserEmail)))
{
EmailErrorText.text = "Invalid Email Format";
UsernameErrorText.text = "";
}
if((IsValidUsername(UserEntername)) && (IsvalidEmailId(UserEmail)))
{
StartCoroutine (StoreData ());
EmailErrorText.text = "";
UsernameErrorText.text = "";
RegisterSuccessfulPanel.gameObject.SetActive(true);
RegisterCheckText.text = "Loading.....";
}
if((!IsValidUsername(UserEntername)) && (!IsvalidEmailId(UserEmail)))
{
EmailErrorText.text = "Invalid Email Format";
UsernameErrorText.text = "Username should be minimum 8 to 12 characters...";
}
}
else
{
DidnotenterText.text = "Please fill above all fields";
}
}
IEnumerator StoreData()
{
username = usernameInputField.text;
emailid = EmailidInputField.text;
password = PasswordInputField.text;
WWWForm form = new WWWForm ();
form.AddField ("username1", username);
form.AddField ("emailid1", emailid);
form.AddField ("password1", password);
WWW download = new WWW( register_url, form );
yield return download;
answer = download.text.ToString ();
if (answer == "Successfully Registered") {
RegisterCheckText.text = "Successfully Registered";
}
else
{
RegisterCheckText.text = "Username or Email Already Existed";
}
if (!string.IsNullOrEmpty (download.error)) {
print ("Error downloading: " + download.error);
ErrorString = download.error;
ErrorMsg.text = ErrorString;
}
else {
}
}
public void OkButton()
{
if (RegisterCheckText.text == "Successfully Registered") {
Time.timeScale = 1;
InternetCheckPanel.gameObject.SetActive (false);
RegisterSuccessfulPanel.gameObject.SetActive (false);
RegisterPanel.gameObject.SetActive (false);
LoginPanel.gameObject.SetActive (true);
usernameInputField.text = "";
PasswordInputField.text = "";
EmailidInputField.text = "";
Join.interactable = false;
usernameInputField.interactable = true;
EmailidInputField.interactable = true;
PasswordInputField.interactable = true;
Join.interactable = true;
} else
if(RegisterCheckText.text == "Username or Email Already Existed")
{
RegisterSuccessfulPanel.gameObject.SetActive (false);
}
}
public static bool IsvalidEmailId(string InputEmail)
{
Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,5})+)$");
Match match = regex.Match (InputEmail);
if (match.Success)
return true;
else
return false;
}
public static bool IsValidUsername(string InputUsername)
{
Regex regex1 = new Regex("^[a-zA-Z]{8,12}$");
Match match1 = regex1.Match (InputUsername);
if (match1.Success)
return true;
else
return false;
}
public void BackButton()
{
RegisterPanel.gameObject.SetActive (false);
LoginPanel.gameObject.SetActive (true);
}
}
Server Side Script :-
======================
<?php
$servername = "Your_ServerName";
$username = "Your_UserName";
$password = "************";
$dbname = "Your_DB_Name";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$exits = 0;
$Username2=$_POST['username1'];
$Emailid2 = $_POST['emailid1'];
$Password2 = $_POST['password1'];
$query = "SELECT * FROM userinfo where username = '$Username2' OR emailid = '$Emailid2'";
$result = mysqli_query($conn,$query);
$num = mysqli_num_rows($result);
if($num == 0)
{
$sql = "INSERT INTO userinfo (username,emailid,password) VALUES ('$Username2','$Emailid2','$Password2')";
$result1 = mysqli_query($conn,$sql);
echo "Successfully Registered";
}
else
{
echo "Username already existed" ;
}
mysqli_close($conn);
?>
No comments:
Post a Comment