Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by zbegra · Jan 29, 2011 at 06:10 PM · onlinemysqlphphighscoresemail

Adding extra information to Server Side Highscores

Good Evening :-)

I have been struggling with the Server Side Highscores example on the unify community wiki for a good two weeks now, and I really, really need to get this working. The script works excellent, everything is fine and I'm loving it. The problems starts when I try to add additional information to the database.

The thing is, I would like to add two things to the database; the users email address and the date when the score was posted. But whenever I try to update the scripts to support this it wont upload to the database anymore. I have update the HSController, the addscores.php and the MySQL tables but I must be doing something wrong somewhere.

Could you maybe help me out in adding these fields to the script? It would be very much appreciated and you will of course be credited for helping :-)

http://www.unifycommunity.com/wiki/index.php?title=Server_Side_Highscores

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DaveA · Jan 29, 2011 at 07:10 PM

You will of course add your extra info in the client script, on this line:

 var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash + "&extra_stuff="+extra_stuff

Then you need to add to the PHP script:

$extra_stuff = mysql_real_escape_string($_GET['extra_stuff'], $db);

$query = "insert into scores values (NULL, '$name', '$score', $extra_stuff);";

And make sure you add fields to your database too.

You can test your PHP by just hitting it with a web browser.

Comment
Add comment · Show 3 · 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 zbegra · Jan 29, 2011 at 08:43 PM 0
Share

Thanks for the answer. That's pretty much what I tried. I tried your code aswell just in case, and I'm having the exact same problem. I'm starting to wonder if it's the hash that fails?

$$anonymous$$ySQL

CREATE TABLE scores ( id int(10) UNSIGNED NOT NULL AUTO_INCRE$$anonymous$$ENT PRI$$anonymous$$ARY $$anonymous$$EY, name varchar(15) NOT NULL DEFAULT 'anonymous', extra_stuff varchar(255) NOT NULL DEFAULT 'anonymous', score int(10) UNSIGNED NOT NULL DEFAULT '0' )

avatar image zbegra · Jan 29, 2011 at 10:05 PM 0
Share

Ok, I think I figured it out. It seems that if you add the fields in the wrong order in the database it will not work, once I had the exact same order in both url and the database then it worked.

avatar image zbegra · Jan 29, 2011 at 10:11 PM 0
Share

It's still not accepting when I do it with the hash though. I commented out the hash stuff and got it to work, any ideas?

avatar image
1

Answer by zbegra · Jan 29, 2011 at 11:54 PM

Allright, I finally got this working. I'll post the full code here so that others can benefit from this in the future

PHP:

<?php $db = mysql_connect('mysql.host.com', 'username', 'password') or die('Could not connect: ' . mysql_error()); mysql_select_db('database') or die('Could not select database');

     // Strings must be escaped to prevent SQL injection attack. 
     $name = mysql_real_escape_string($_GET['name'], $db); 
     $score = mysql_real_escape_string($_GET['score'], $db);
     $email = mysql_real_escape_string($_GET['email'], $db); 
     $date = date("d/m/Y");
     $hash = $_GET['hash']; 

     $secretKey="replacewithyourown"; # Change this value to match the value stored in the client javascript below 

     $real_hash = md5($name . $score . $secretKey); 

     if ($real_hash != $hash) {
     die('haha, try again sucker');  
     }

     if($real_hash == $hash) { 
         // Send variables for the MySQL database class. 
         $query = "insert into scores values (NULL, '$name', '$score', '$email', '$date');"; 
         $result = mysql_query($query) or die('Query failed: ' . mysql_error()); 
     } 

?>

Javascript:

private var secretKey="replacewithyourown"; // Edit this value and make sure it's the same as the one stored on the server var addScoreUrl="http://replacewithyourown.com/addscore.php?"; //be sure to add a ? to your url var highscoreUrl="http://replacewithyourown.com/display.php";

function postScore(name, score, email) { //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. var hash=md5functions.Md5Sum(name + score + secretKey);

var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&email=" + WWW.EscapeURL(email) + "&hash=" + hash ;

 // Post the URL to the site and create a download object to get the result.
 hs_post = WWW(highscore_url);
 yield hs_post; // Wait until the download is done
 if(hs_post.error) {
     print("There was an error posting the high score: " + hs_post.error);
 }

}

// Get the scores from the MySQL DB to display in a GUIText. function getScores() { gameObject.guiText.text = "Loading Scores"; hs_get = WWW(highscoreUrl); yield hs_get;

 if(hs_get.error) {
     print("There was an error getting the high score: " + hs_get.error);
 } else {
     gameObject.guiText.text = hs_get.data; // this is a GUIText that will display the scores in game.
 }

}

MySQL Table:

CREATE TABLE `scores` (
   `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
   `name` varchar(15) NOT NULL DEFAULT 'anonymous',
   `score` int(10) UNSIGNED NOT NULL DEFAULT '0' ,
   `email` varchar(255) NOT NULL DEFAULT 'anonymous',
   `date` varchar(15) NOT NULL DEFAULT 'anonymous'

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 lucas 1 · May 09, 2011 at 06:24 PM

Assets/all/score/score.js(36,13): BCE0005: Unknown identifier: 'Md5'. error how can souve?

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 n4zg · Jun 23, 2012 at 04:33 PM

I have set up the db and its working with Server Side Highscores script. i am getting stuck in adding data automatically eg when a coin is collected in a game a score is added live onto the sql . any suggestions ?

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

1 Person is following this question.

avatar image

Related Questions

Android Mysql Database online 3 Answers

PHP HighScore Position 1 Answer

Unify "serverside highscores" - reading in a webpage 1 Answer

Trying to get server side highscores working with MySQL. Apparently I need a Secret Key for my database. What is that? How do I get one? 1 Answer

Using PHP to generate objects or list in Unity with C# 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