Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm creating a mysql database for my android app to save and load a top 10 highscore system. I've some knowledge of php and mysql over the years however I'm no expert. Any help is appreciated:

The full code is:

<?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;

and it breaks on line 8:

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS)
    or die('Could not connect: ' . mysql_error());
share|improve this question
1  
Is this code exactly as it's running on your server? If you've changed it, it'll be impossible for us to identify the problem since it's a Parse Error. Also, may be worth looking at mysqli, as the mysql extension is now deprecated. –  ollieread Dec 18 '13 at 0:08
    
@RiggsFolly there is a parse error, so mysql_error() won't ever run. Besides, mysql_error() wouldn't cause a parse error, no matter what it returned. –  ollieread Dec 18 '13 at 0:09
    
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect to DB'); I think you don't need mysql_error() it wouldnt be relevant in this case –  meda Dec 18 '13 at 0:11
1  
Personally, I would take this time to change from PHP mysql_* functions to mysqli_* ones. It is also possible this could be at least part of the issue. –  Tigger Dec 18 '13 at 0:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.