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 TehWut · Jul 19, 2012 at 03:22 PM · serverdatabasesqlhighscore

Server Side Highscore "There was an error getting the high score: 404 not found"

I'm following the tutorial found on the wiki on how to create server side high scores. found here Here is my current set up:

addscore.php

 <?php 
     $db = mysql_connect('localhost', 'root', 'wiiwowut') or die('Could not connect: ' . mysql_error()); 
     mysql_select_db('test') 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); 
     $hash = $_GET['hash']; 
     
     $secretKey="99669900"; # Change this value to match the value stored in the client javascript below 

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

?>

displayscore.php

 <?php
 // Send variables for the MySQL database class.
 $database = mysql_connect('localhost', 'root', 'wiiwowut') or die('Could not connect: ' . mysql_error());
 mysql_select_db('test') or die('Could not select database');

 $query = "SELECT * FROM `scores` ORDER by `score` DESC LIMIT 5";
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());

 $num_results = mysql_num_rows($result);  

 for($i = 0; $i < $num_results; $i++)
 {
      $row = mysql_fetch_array($result);
      echo $row['name'] . "\t" . $row['score'] . "\n";
 }

?>

hscontroller.js

     private var secretKey="99669900"; // Edit this value and make sure it's the same as the one stored on the server
 var addScoreUrl="http://localhost/addscore.php?"; //be sure to add a ? to your url
 var highscoreUrl="http://localhost/display.php";    
 
 function Start() {
     getScores();
 }
 
 function postScore(name, score) {
     //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=Md5.Md5Sum(name + score + secretKey); 
 
     var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&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.text; // this is a GUIText that will display the scores in game.
     }
 }

What does 404 mean? is it an error with my database setup? MYSQL setup? did I not name something properly in the code?

I"m using Apache 2.2 webserver and PHP, both which seem to be working fine. Or could there really be an issue here?

EDIT: using a test PHP from the localhost

   <?php     $database = mysql_connect('localhost', 'root', 'wiiwowut') or die('Could not connect: ' . mysql_error());
     mysql_select_db('test') or die('Could not select database');
  echo (&quot;sucessfully connected, hooray!&quot;);
 ?&gt;

yielded sucessful. This has to be an issue within the unity code.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by IndieScapeGames · Jul 19, 2012 at 04:15 PM

404 simply put means the server cannot find the requested file.

You're hosting on your localhost, which is fine, but based on previous Apache experience, you may need to specify the port. If you're using the default port, I don't know why it might not be forwarding automatically.

 var addScoreUrl="http://localhost:80/addscore.php?"; //added default port number
 var highscoreUrl="http://localhost:80/display.php"; //added default port number
Comment
Add comment · Show 1 · 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 TehWut · Jul 19, 2012 at 05:34 PM 0
Share

Huh. Well I tried messing around with that, but to no avail. Could it be anything else?

avatar image
1

Answer by FredVicentin · Jul 19, 2012 at 04:15 PM

Probably a Firewall problem or a modem problem, check if you have a problem on port, and test your mySQL// Apache to see if it works, do some score and them see if the value on DB changed, if it don't change, can be a index problem, check if you have an index and if the table value is right, like a float variable, etc, check the names and your modem, something can be blocking it.

Comment
Add comment · Show 1 · 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 TehWut · Jul 19, 2012 at 05:35 PM 0
Share

disabled firewall, added inbound rule etc. and didn't help at all. Thanks though.

avatar image
0

Answer by TehWut · Jul 19, 2012 at 08:52 PM

ಠ_ಠ

well, out of all my obvious solutions, this was the worst one. It should've been

 var highscoreUrl="http://localhost/displayscore.php";    

instead of

  var highscoreUrl="http://localhost/display.php";  
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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best way to connect to database for my mobile game? 3 Answers

Microsoft SQL Server error. 0 Answers

Hosted Database for Mobile Game 0 Answers

Web-Client / Dedicated Console Server? 1 Answer

php, sql security 3 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