Advertisement
Teammasik

DB_project_hints

May 18th, 2023
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Registr : MonoBehaviour
  7. {
  8.     public InputField groupfield;
  9.     public InputField namefield;
  10.     public InputField surnamefield;
  11.  
  12.     public Button submitButton;
  13.  
  14.     public void CallRegister()
  15.     {
  16.         StartCoroutine(Register());
  17.  
  18.     }
  19.  
  20.     IEnumerator Register()
  21.     {
  22.         WWWForm form = new WWWForm();
  23.         form.AddField("name", namefield.text);
  24.         form.AddField("surname", surnamefield.text);
  25.         form.AddField("group", groupfield.text);
  26.         WWW www = new WWW("http://localhost/sqlconnect/register.php", form);
  27.         yield return www;
  28.         if (www.text == "0"){
  29.             Debug.Log("User created ");
  30.         }
  31.         else
  32.         {
  33.             Debug.Log("User creation failed:" + www.text);
  34.         }
  35.     }
  36.  
  37.     public void VerifyInputs()
  38.     {
  39.         submitButton.interactable = (namefield.text.Length >= 2 && surnamefield.text.Length >= 4);
  40.     }
  41.  
  42. }
  43.  
  44. ----------------------------------------------------
  45. php:
  46. <?php
  47.  
  48.     $con = mysqli_connect('localhost','root','root','unityaccess');
  49.    
  50.     if (mysqli_connect_errno())
  51.     {
  52.         echo "1";
  53.         exit();
  54.     }
  55.    
  56.     $username = $_POST["name"];
  57.     $usersurname = $_POST["surname"];
  58.     $usergroup = $_POST["group"];
  59.  
  60.     $insertuserquery = "INSERT INTO students (username,usersurname,usergroup) VALUES ('" . $username . "', '" . $usersurname ."', '" .$usergroup ."');";
  61.     mysqli_query($con, $insertuserquery) or die ("4: insert failed");
  62.  
  63.     echo("0");
  64.  
  65. ?>
  66.  
  67.  
  68.  
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement