Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Lunehtik · Feb 01, 2018 at 02:31 PM · wwwmysqlphpwwwform

Problem using WWW with PHP and MYSQL

I've set up a MySQL database, PHP script, and a C# script to try and setup a registration service. The database seems to be working correctly. When I access my PHP script through my browser it works correctly creating a username and password in my MySQL database. When I run my C# script through unity however it does not create a username or password at all. I cannot find what the issue would be if someone could help me out id be very appreciative.

PHP code:

     $username = $_POST["usernamePost"];
     $password = $_POST["passwordPost"];
     
     //Make Connection
     $connection = new mysqli($servername, $serverusername, $serverpassword, $serverdatabasename);
     
     //Check Connection
     if(!$connection){
         die("Connection failed. ". mysqli_connect_error());
     }
     
     $check = "SELECT * FROM accounts WHERE `username`='".$username."'";
     $result = mysqli_query($connection , $check);    
     $numrows = mysqli_num_rows($result);
     if ($numrows == 0)
     {
         $pass = md5($password);
         $ins = "INSERT INTO accounts (`username` ,  `password`) VALUES ('".$username."' ,  '".$password."')";
         $result = mysqli_query($connection , $ins);    
         if ($result)
             die ("Successfully Created User!");
         else
             die ("Error: ");
     }
     else
     {
         die("User already exists!");
     }
 ?>

C# Script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

 public class DataInserter : MonoBehaviour {
 
     public InputField inputUsername;
     public InputField inputPassword;
 
     string createUserURL = "http://localhost/NewUser.php";
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown(KeyCode.Space)) Register(inputUsername.text, inputPassword.text);
     }
 
     public void Register(string username, string password)
     {
         StartCoroutine(CreateUser(username, password));
     }
 
 
     IEnumerator CreateUser(string username, string password)
     {
         WWWForm form = new WWWForm();
         form.AddField("usernamePost", username);
         form.AddField("passwordPost", password);
 
         WWW www = new WWW(createUserURL, form);
         Debug.Log(www.error);
         Debug.Log(www.text);
         yield return www;
         if (www.error != null)
         {
             Debug.Log("Something went wrong");
         }
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by awtrimpe · Feb 15, 2018 at 03:21 PM

Not sure, but the problem might be from trying to run the PHP from your local computer. Try uploading to a server and seeing.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Zodiarc · Feb 15, 2018 at 03:41 PM

Have you tried "http://127.0.0.1/NewUser.php"? Maybe somehow the C# script cannot resolve the name correctly.

And some general notes:

MD5 hash for a password - just don't. Instead of using mysqli, use PDO at the very least and use prepared statements. This way you'll prevent SQL injection. If possible, switch to an ORM. Also don't make scripts die if the query was successful. You can just echo the message.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by 2000noe · Feb 16, 2018 at 09:44 AM

Try updating your unity to the latest version, that did it for me

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

78 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WWWForm.Addfield not able to post data to server 1 Answer

Why isn't this $_POST working properly? 1 Answer

wwwform send an array the right way! 0 Answers

Would a WWW to a PHP file return the computers Info? 0 Answers

C # Does not recognize characters after space 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges