So I’ve looked at a few tutorials about communicating between MySql and C# scripts in Unity. When I run the Coroutine, the console tells me that the upload was completed successfully; however, when I run SELECT * FROM StudentUsers in my terminal, it says empty set. Now, I know I have an error with something somewhere but i don’t know where… Thanks for the help.
My PHP Script:
<?php
$db = mysql_connect('localhost', '****', '****') or die('Could not connect: ' . mysql_error());
mysql_select_db('MFHS_FanApp_db') or die('Could not select database');
// Strings must be escaped to prevent SQL injection attack.
$first_name = mysql_real_escape_string($_GET['first_name'], $db);
$last_name = mysql_real_escape_string($_GET['last_name'], $db);
$username = mysql_real_escape_string($_GET['username'], $db);
$email = mysql_real_escape_string($_GET['email'], $db);
$password = mysql_real_escape_string($_GET['password'], $db);
$grad_year = mysql_real_escape_string($_GET['grad_year'], $db);
$points = mysql_real_escape_string($_GET['points'], $db);
$hash = $_GET['hash'];
$secretKey="mySecretKey"; # Change this value to match the value stored in the client javascript below
$real_hash = md5($first_name . $last_name . $username . $email . $password . $grad_year . $points . $secretKey);
if($real_hash == $hash) {
// Send variables for the MySQL database class.
$query = "insert into StudentUsers values (NULL, '$first_name', '$last_name', '$username', '$email', '$password', '$grad_year', '$points');";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
}
?>
My C# Method:
IEnumerator AddStudentUser(string first_name, string last_name, string username, string email, string password, int grad_year, int points)
{
print ("Begin AddStudentUser");
//This connects to a server side php script that will add the name and score to a MySQL DB.
// Supply it with a string representing the players name and the players score.
string hash = Md5Sum(first_name + last_name + username + email + password + grad_year + points + secretKey);
string post_url = URL_addStudentUser + "first_name=" + WWW.EscapeURL(first_name) + "&last_name=" + WWW.EscapeURL(last_name) + "&username=" + WWW.EscapeURL(username) +
"&email=" + WWW.EscapeURL(username) + "&password=" + WWW.EscapeURL(username) + "&grad_year" + grad_year + "&points=" + points + "&hash=" + hash;
print (post_url);
// Post the URL to the site and create a download object to get the result.
WWW hs_post = new WWW(post_url);
yield return hs_post; // Wait until the download is done
if (hs_post.error != null)
{
print("There was an error posting the high score: " + hs_post.error);
} else {
print ("Successfully uploaded");
}
}