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
// 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>';
}
}
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.
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 :)
Your answer
Follow this Question
Related Questions
Get Internet Year PHP 0 Answers
error in posting highscore to server 0 Answers
Where can I download Android Build Support 5.3.1f1? 1 Answer
html line break doesn't work in unity? 0 Answers