PHP MySQL:解析错误:语法错误,意外T_VARIABLE

时间:2013-12-18 00:04:35

标签: php mysql sdk corona

我正在为我的Android应用程序创建一个mysql数据库来保存并加载前10个高分系统。多年来我对php和mysql有一些了解,但我不是专家。任何帮助表示赞赏:

完整的代码是:

<?php
define("DB_DSN",'yourdbname');
define("DB_HOST",'localhost');
define("DB_USER",'yourdblogin');
define("DB_PASS",'yourdbpass');
 
// Connecting, selecting database
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect: ' . mysql_error());
mysql_select_db(DB_DSN) or die('Could not select database');
 
if(isset($_GET)) {
    $playername = base64_decode($_GET["playername"]);
    $password = base64_decode($_GET["password"]);
    $query = 'SELECT * FROM players WHERE playername="' . mysql_real_escape_string($playername) . '" or email="' . mysql_real_escape_string($loginid) . '"';
    $dbresult = mysql_query($query, $link);
    if (!$dbresult) {
        //echo "query failed";
        $result = array();
        $result["result"] = 403;
        $result["message"] = mysql_error();
        echo json_encode($result);
        mysql_free_result($dbresult);
        exit;
    }
    $player = mysql_fetch_array($dbresult, MYSQL_ASSOC);
    if (strcmp($player["password"],md5($password)) == 0) {
        $result = array();
        $result["result"] = 200;
        $result["message"] = "Success";
        $result["playername"] = $player["playername"];
        $result["firstname"] = $player["firstname"];
        $result["lastname"] = $player["lastname"]; 
        $query = sprintf("UPDATE players SET lastlogin=NOW() WHERE id=%s;", $player["id"]);
        $uresult = mysql_query($query, $link);
        if ($uresult) {
            //code if your update failed.  Doesn't really impact what we are doing. so do nothing.
        }
        echo json_encode($result);
    } else {
        //echo "password mismatch";
        $result = array();
        $result["result"] = 403;
        $result["message"] = "Forbidden";
        echo json_encode($result);
    }
} else {
    $result = array();
    $result["result"] = 400;
    $result["message"] = "Bad Request";
    echo json_encode($result);
}
exit;

它在第8行打破:

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS)
    or die('Could not connect: ' . mysql_error());

1 个答案:

答案 0 :(得分:0)

不确定您是否已修复此问题。很久以前。

但是你可以在php代码或查询中轻松找到错误。

  1. 开始将以下内容添加到php文件的顶部(打开后立即打开[

    的error_reporting(E_ALL);   ini_set('display_errors','on');

  2. 这将显示您在页面上有哪些php错误。

    1. 然后使用

      检查您的查询错误
      $sql = your sql query
      $query = mysqli_query($link, "$sql") or die(mysqli_error($link);
      
    2. 第二个将打印mysql错误,然后您可以使用它来修复您的问题。

      您可以随时使用上述内容来查找问题。