• 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 /
  • Help Room /
avatar image
0
Question by prateek1234 · May 02, 2017 at 06:58 PM · phpwebsiteserver-hosting

getting error undefine index in uploading score

i am using this tutorial http://wiki.unity3d.com/index.php?title=Server_Side_Highscores

i am getting an error

Notice: Undefined index: name in addscore.php on line 16

Notice: Undefined index: score in addscore.php on line 16

Notice: Undefined variable: hash inaddscore.php on line 17

this is my pdo script

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 prateek1234 · May 02, 2017 at 07:04 PM 0
Share
     // Configuration
     $hostname = 'localhost';
     $username = 'idprateek';
     $password = '12345';
     $database = 'high';
 
     $secret$$anonymous$$ey = "123546789"; // Change this value to match the value stored in the client javascript below 
 
     try {
         $dbh = new PDO('mysql:host='. $hostname .';dbname='. $database, $username, $password);
     } catch(PDOException $e) {
         echo '<h1>An error has ocurred.</h1><pre>', $e->get$$anonymous$$essage() ,'</pre>';
     }
 
     $realHash = md5($_GET['name'] . $_GET['score'] . $secret$$anonymous$$ey); 
     if($realHash == $hash) { 
         $sth = $dbh->prepare('INSERT INTO scores VALUES (null, :name, :score)');
         try {
             $sth->execute($_GET);
         } catch(Exception $e) {
             echo '<h1>An error has ocurred.</h1><pre>', $e->get$$anonymous$$essage() ,'</pre>';
         }
     } 

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jawchewa · May 03, 2017 at 01:19 AM

It looks like the error is that you are never defining the variable $hash, and that the indexes for name and score are never set.

Looking at the tutorial, I noticed a line that says, "Please! This code need to be tested. Tested, confirmed not working. Use snippet above. " I would probably recommend trying the first code snippet example, instead of the second one, and seeing where that takes you.

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 CurtisGM · Feb 28, 2018 at 11:58 PM

Although this response is quite late, this is for those of you who come to this particular question also looking for an answer.

As Jawchewa mentioned, $hash was never defined as well as the indexes when executing the command. Here is an updated version that I have modified and tested.

 <?php
         // Configuration
         $hostname = 'INSERT_HOSTNAME_HERE';
         $username = 'INSERT_USERNAME_HERE';
         $password = 'INSERT_PASSWORD_HERE';
         $database = 'INSERT_DATABASE_HERE';
  
         $secretKey = "INSERT_SECRET_KEY_HERE"; // Change this value to match the value stored in the client javascript below 
  
         try {
             $dbh = new PDO('mysql:host='. $hostname .';dbname='. $database, $username, $password);
         } catch(PDOException $e) {
             echo '<h1>An error has ocurred.</h1><pre>', $e->getMessage() ,'</pre>';
         }
 
         $username = $_GET['name'];
         $userscore = $_GET['score'];
 
         $realHash = md5($_GET['name'] . $_GET['score'] . $secretKey);
         $hash = $_GET['hash'];
  
         if($realHash == $hash) { 
             $sth = $dbh->prepare('INSERT INTO scores VALUES (null, :username, :userscore)');
             try {
                 $sth->execute(['username' => $username, 'userscore' => $userscore]);
             } catch(Exception $e) {
                 echo '<h1>An error has ocurred.</h1><pre>', $e->getMessage() ,'</pre>';
             }
         } 
 ?>

Hopefully someone finds this useful :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

101 People are following this question.

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

Related Questions

Unity Web view error. make a transaction using unity web view payment details and payment page open but response page not open. how to solve this ? 0 Answers

error in posting highscore to server 0 Answers

Get Internet Year PHP 0 Answers

get value from website 1 Answer

Where to report broken lesson? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges