php mysql code not working. suggestions?

[php]<?php

$Email = $_REQUEST[“CEmail”];
$Password = $_REQUEST[“CPassword”];

$Hostname = “fdb.awardspace.net”;
$DBName = “1946_accounts”;
$User = “1946_accounts”;
$PasswordP = “********”;

mysql_connect($Hostname, $User, $PasswordP) or die(“Can’t connect to DB”);
mysql_select_db($DBName) or die(“Can’t connect to DB”);

if(!$Email || !$Password){
echo"Empty";
}else{
$SQL = “SELECT * FROM accounts WHERE Email = '” . $Email . “’”;
$Result = @mysql_query($SQL) or die(“DB Error”);
$Total = mysql_num_rows($Result);
if($Total == 0){
$insert = “INSERT INTO accounts (‘Email’, ‘Password’, ‘Characters’) VALUES (’” . $Email . “’, MD5(’” . $Password . “’), 0)”;
$SQL1 = mysql_query($insert);
echo “Success”;
}else{
echo “AlreadyUsed”;
}
}

mysql_close();
?>[/php]

i have a c# script in unity, calling the url of the php script. when i direct connect to the php script it shows “empty” so it is making it that far into the script. when i try sending data to the db table from unity, it never makes it through and i never get errors back. I’m under the impression my else block is missing something.

could someone correct this code or help me out?

I alter some information posted, didn’t think you would want that public.

Don’t use mysql_ functions; don’t use MD5 to hash passwords; use prepared statements (this is made easier with PDO).

How are you passing the values to the script? If you are getting to the point that “Empty” is showing, then there is an issue with the script receiving the (hopefully) post values, unless you are hashing or encrypting the values from the c# application to the PHP script?

Oh, wow. Thank you for changing the pw; clearly I’ve gotten more tired than I realized.

So, from the c#, a button gets pressed and this gets called:

[code]IEnumerator CreateAccount() {

	WWWForm Form = new WWWForm();			//Send info to our PHP script

	Form.AddField("Email", CEmail);			
	Form.AddField("Password", CPassword);

	WWW CreateAccountWWW = new WWW(CreateAccountURL, Form);
	Debug.Log("Contacting Server");

	yield return CreateAccountWWW;			//waits for PHP to send something back to Unity

	if(CreateAccountWWW.error != null) {
		Debug.LogError("Cannot create to account creation");
		Debug.LogError(CreateAccountWWW.error as string);
	}else{
		string CreateAccountReturn = CreateAccountWWW.text;
		if(CreateAccountReturn == "Success") {
			Debug.Log("Successful Account Created");
			CurrentMenu = "Login";
		}
	}
}[/code]

When this gets called, the Debug.Log for “Contacting Server” is the last debug that gets called. Nothing is returned from the php script.

Break your PHP code down to simpler functionality for now. Try this:
[php]

<?php print_r( $_REQUEST );[/php] In whatever page your app is set to contact. See if and what is getting to it. Then you can build it up from there.

You aren’t passing in any value to this function. So, are CEmail and CPassword passing values?

The c# code also only reports if there is an error or an explicit “SUCCESS”. So, if something else was to be returned, it would fail silently.

CEmail and CPassword get defined prior to the button getting pushed. I mangled this from a tutorial specifically for creating a registration system, and am thinking I should just start fresh and learn how to write a better version anyway since you recommend not using mysql_functions and not using MD5 to hash.

Hopefully, you are already versed in C#? For the PHP side of things, PDO is the way to go for database manipulation and most current hashing algorithms work, they are the same across languages.

I am decently versed in C#, but not so much in server side stuff. Can I message you with questions? (They are likely to vary in specifics, so I figure a thread would not be appropriate.)

Sponsor our Newsletter | Privacy Policy | Terms of Service