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 wimlore · May 07, 2012 at 06:08 AM · c#tutorialmysqlhighscoreshtml

C# Passing string to PHP for a MySQL table : Sever Side Highscore Tutorial

Hello! I follow this tutorial closely and understand the jist of it: Server Side Highscores Tutorial. I got it functioning properly but I wish to make it more dynamic. I managed to pass the name of the MySQL table name for posting scores via the addscore.php script, successfully. This is all so I can use this php scripts for multiple tables, related to different games. I tried doing the same for the display.php but for the life of me I can not get it to work!

In my unity C# script I am only able to get a connection by having my URL contain the variable as well (For some reason concenating the URL will cause a 404 error, i.e. URL + "scoreTable=" + scoretable)

Heres the relative C# code:

 public string highscoreURL = "http://website.com/display.php?scoreTable=clicking_game";

     IEnumerator GetScores() {
     gameObject.guiText.text = "Loading Scores";
     WWW hs_get = new WWW(highscoreURL);
     yield return hs_get;
     gameObject.guiText.text = hs_get.text;
 }


And the modified display.php:

 <?php
 // Send variables for the MySQL database class.
 $database = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error());
 mysql_select_db('my_database') or die('Could not select database');

 $scoreTable = $_GET['scoreTable'];
 $query = "SELECT * FROM `$scoreTable` 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";
 }

?>

Just to be extra clear, all I am doing here is changing the 'scores' table used in the example to a variable that is passed from unity. This does not work for me however, it says the querey failed because the table does not exist, and the table passed is just ''. So connection is being made, and the scoreTable variable is being declared in the PHP script and being used in the querey. But, for some reason my C# code just isn't passing the string properly. Either that or the PHP script isn't setting the variable properly.

Any helps or tips would be highly appreciated, thanks!

Comment
Add comment · Show 1
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 rutter · May 07, 2012 at 06:34 AM 0
Share

You can probably narrow down your problem by deter$$anonymous$$ing the first step in the process that's producing unexpected results -- everything after that step will probably be broken.

For example, you could try echoing the variable directly from your PHP script, to make sure that it looks right. If it does, then you know something's going wrong with your SQL call; if not, then you know it's an earlier step in the process.

Figuring out which step broke is often half of the battle, at least.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by wimlore · May 07, 2012 at 03:19 PM

Rutter! Thank you for your encouraging words of wisdom. I did as you said, and rooted out the broken step. The issue was with the URL I was trying to access. I printed the URL string as I was attempting to connect to it via WWW, and for some reason it was removing the '?' character at the end of the URL, just before the 'scoreTable='. Why? I have no clue!! But now that I know that, I was able to concenate URL string with "?scoreTable=" and it worked. So everything I was doing was correct as far as I can see. Something within Unity was qwerking my URL string and holding me back for... far... too... long... Glad I can move on :D

So heads up dudes, sometimes Unity will remove the '?' character at the end of your URL. I can not find the reason for it. Thanks again Rutter :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

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

MySql SocketException: The attempt to establish a connection was unsuccessful, because the desired response was not received from another computer in the required time, or an already established connection was terminated 0 Answers

Simple c# Character Controller + Animations / Side-scroller 0 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