- Home /
sending values to server script
Hi all, I am new to this unity world and to PHP, the following question may seems repeated but I am stuck in this - I am trying to send values from Unity content to server script, I followed this link to initiate 1. But I am not getting any values in server(configured in the same system) side. I am running my PHP using "EasyPHP" tool. When I run my program in Unity editor it is showing as data sent , and when i run my PHP ,it is showing as
Notice: Undefined index: username in C:\Program Files\EasyPHP-5.3.6.0\www\LoginTest.php on line 2
Notice: Undefined index: passwordscore in C:\Program Files\EasyPHP-5.3.6.0\www\LoginTest.php on line 3
Following are my code snippets , please help me in where am i going wrong- PHP file at server side -
Login.php
<?php echo $_POST['username']; ?>
<?php echo $_POST['passwordscore']; ?>
Javascript File in Unity-
Login.js
// start var userNameToEdit : String = "Your ID";
var passwordToEdit : String ;
var form:WWWForm;
var LoginTestURL = "http://127.0.0.1:8888/Login.php";
function Start() { // Create a form object for sending high score data to the server form = new WWWForm(); }
function OnGUI () { // Make a text field that modifies stringToEdit. userNameToEdit = GUI.TextField (Rect (110, 10, 200, 20), userNameToEdit, 10);
// Make a password field that modifies passwordToEdit.
passwordToEdit = GUI.PasswordField (Rect (110, 40, 200, 20), passwordToEdit, "*"[0], 10);
if (GUI.Button(Rect(110,70,60,25),"Login"))
{
print("Clicked the button with text");
print(userNameToEdit);
print(passwordToEdit);
sendLoginData();
}
}
function sendLoginData() { form.AddField( "username", userNameToEdit );
form.AddField( "password", passwordToEdit);
var w = new WWW(LoginTestURL, form);
yield w;
if (w.error != null)
print(w.error);
else
print("Finished Uploading LoginData");
} function Update () {
}
Login.js end
I have one more problem that it is started showing "Finished Uploading LoginData" even i give wrong URL. Please suggest something on the above problem.
Thanking All in advance-
Answer by DaveA · Apr 30, 2011 at 05:22 PM
What do you mean by 'run PHP'?
What I usually do is make a stand-alone HTML page (for POST forms), or use GET and just hit the URL, to test the PHP by itself and make sure it's working.
In your script, add Debug.Log("Got back:"+w.text); to see what comes back
Hey thanks for the reply.. I tested my PHP with two defferent files to pass values between them and they r working fine on web. And when come to javascript, i added Debug.Log statement , I got an error which says Object not found. And it sorted out by creating new project and code i inserted the same thing and guess what it worked and printed back my Username and Password on webplayer.
The object not found must have been the w for some reason. Has it helped at all?
Your answer
![](https://koobas.hobune.stream/wayback/20220613130449im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Getting info using WWW & PHP 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
www class works fine in android but doesn't work in ios... 0 Answers
modernized master server script? 1 Answer
Is it possible to have a server deliver complete levels to an otherwise empty client? 1 Answer