Unity3d(C#,PHP)排行榜
大家好,我的php脚本有问题,它说 注意:未定义索引:中的名称 /第16行的storage/h6/881/1096881/public_html/InsertScore.php 注意:未定义索引:中的分数 /第16行的storage/h6/881/1096881/public_html/InsertScore.php 注意:未定义变量:散列 /第17行的storage/h6/881/1096881/public_html/InsertScore.phpUnity3d(C#,PHP)排行榜,php,Php,大家好,我的php脚本有问题,它说 注意:未定义索引:中的名称 /第16行的storage/h6/881/1096881/public_html/InsertScore.php 注意:未定义索引:中的分数 /第16行的storage/h6/881/1096881/public_html/InsertScore.php 注意:未定义变量:散列 /第17行的storage/h6/881/1096881/public_html/InsertScore.php 试试看{ $dbh=newpdo('mys
试试看{
$dbh=newpdo('mysql:host='.$hostname.';dbname='.$database,$username,$password);
}捕获(PDO$e){
echo“出现错误”,$e->getMessage(),“”;
}
$realHash=md5($\u GET['Name'].$\u GET['Score'].$secretKey);
如果($realHash==$hash){
$sth=$dbh->prepare('INSERT-INTO-getdataofplayer-VALUES(null,:Name,:Score)');
试一试{
$sth->execute($\u GET);
}捕获(例外$e){
echo“出现错误”,$e->getMessage(),“”;
}
}
答案就在你的问题中。注意:未定义索引。和@Condorcho紧跟在tut后面这里//必须转义字符串以防止SQL注入攻击$name=mysql\u real\u escape\u字符串($\u GET['name',$db)$score=mysql\u real\u escape\u字符串($\u GET['score',$db)$hash=$\u GET['hash']代码>你错过了那部分。我使用PDO查询是的,误读了。您只需要定义未定义的变量$name=$\u GET['name']
等。请记住在插入之前进行消毒。答案在于您的问题。注意:未定义索引。和@Condorcho紧跟在tut后面这里//必须转义字符串以防止SQL注入攻击$name=mysql\u real\u escape\u字符串($\u GET['name',$db)$score=mysql\u real\u escape\u字符串($\u GET['score',$db)$hash=$\u GET['hash']代码>你错过了那部分。我使用PDO查询是的,误读了。您只需要定义未定义的变量$name=$\u GET['name']
等。请记住在插入前进行消毒。
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>';
}
$realHash = md5($_GET['Name'] . $_GET['Score'] . $secretKey);
if($realHash == $hash) {
$sth = $dbh->prepare('INSERT INTO getdataofplayer VALUES (null, :Name, :Score)');
try {
$sth->execute($_GET);
} catch(Exception $e) {
echo '<h1>An error has ocurred.</h1><pre>', $e->getMessage() ,'</pre>';
}
}