[Question] Unity > PHP > MySQL

I have seen some tutorials on how to do it for High Scores and Registration but none seem to be working for me.

Are classes like WWW WWWForm restricted to Web Player builds or can i use them on Standalone builds as well? And if so what are my options?

I initially figured it would not work considering POST GET are passed via URL but I’ve seen things that suggest otherwise.

I keep getting 404 errors.

Here’s My Unity JS:

#pragma strict

private var formNick = "";
private var formPassword = "";
var formText = "";

var URL = "http://www.testsite.com/login.php";
var hash = "O.O";

private var textrect = Rect(10,150,200,200);


function OnGUI()
{
    GUI.Label( Rect (10, 10, 80, 20), "Username:" );
    GUI.Label( Rect (10, 30, 80, 20), "Password:" );
	
	formNick = GUI.TextField ( Rect (90, 10, 100, 20), formNick );
	formPassword = GUI.TextField ( Rect (90, 30, 100, 20), formPassword );

 

    if ( GUI.Button ( Rect (10, 60, 100, 20) , "Register" ) )
    {
        Register();
    }
    GUI.TextArea( textrect, formText );
}


function Register()
{
	var form = new WWWForm();
	form.AddField("myform_hash", hash);
	form.AddField("myform_nick", formNick);
	form.AddField("myform_pass", formPassword);

	var w = WWW(URL, form);
    yield w;

	if (w.error != null)
	{
		print(w.error);
	}
    else
	{
		print("Test ok");
		formText = w.data; //here we return the data our PHP told us
		w.Dispose(); //clear our form in game
	}
	// Whipe Vars
    formNick = "";
    formPassword = "";
}

Here’s My PHP:

<?php
// Include Database Connections
include_once "../includes/connections.php";

$unityHash = $_POST["myform_hash"];

$phpHash = "O.O";
$nick = $_POST["myform_nick"]; 
$pass = md5($_POST["myform_pass"]);

if(!$nick || !$pass) 
{
	echo "Fields can not be empty.";
}
else
{
	if ($unityHash != $phpHash)
	{
		echo "O.o Really?";
	} 
	else 
	{
		$checkuser = mysql_query("SELECT Username FROM ds_accounts WHERE Username='$nick'"); 
		$username_exist = mysql_num_rows($checkuser);
		if($username_exist > 0)
        {
			echo "I'm sorry but the username you specified has already been taken.  Please pick another one.";
			unset($nick);
			exit();
        }
        if($username_exist = 0)
		{
            $query = "INSERT INTO ds_accounts (Username, Password)
            VALUES('$nick', '$pass')";
            mysql_query($query) or die(mysql_error());
            mysql_close();
            echo "You have successfully Registered";
		}
	}
}

By default WWW is a GET. If you pass the WWW a WWWForm then it turns into a POST. You can use these in a standalone no problem (in fact, you can use WWW to load data off the disk in a standalone which can sometimes be a nice alternative to System.IO).

404 is page not found so something is wrong with your URL or your web server. Verify by navigating to your URL in a browser.

Roger that. Have it all working smoothly now.

That’s ingenious. I never thought of that. Thank you.

Any ideas how i can recive more variables from php once ?