An SQL error I simply cant get to the bottom of!

Discussion in 'MySQL' started by Chuckun, Apr 11, 2009.

  1. #1
    EDIT: I HAVE RESOLVED THIS ISSUE.

    Everything was going well with my new project untill now. I have desperately tried to resolve an issue I have with my SQL insertions with PHP.

    Heres the part with an error
    $sql = "SELECT `highscore` FROM `games` WHERE `gameid`='" . $game_id . "';";
    $query = mysql_query($sql);
    if (mysql_num_rows($query)) {
    	$row = mysql_fetch_array($query);
    	echo $row["highscore"];     // This line is just for debugging purposes
    	if ($thescore > $row['highscore']) {
    		mysql_query("UPDATE `games` SET `highscore`='" . $thescore. "' WHERE `gameid`='" . $game_id . "';");
    	}
    mysql_query("UPDATE `games` SET `plays` = `plays` +1 WHERE `gameid`='" . $game_id . "';");
    }
    PHP:
    The echo on line 6 fails, (but right up untill the mysql_fetch_array() works fine, I have proved it by echoing all previous values...) So basically, I've located the error to be from the line: $row = mysql_fetch_array($query);, and thus deeming the 3 lines after; useless.

    Can anyone see where I've gone wrong?

    by the way, $thescore and $game_id are definitely defined and working.. the echo is the first and only echo I tested which fails to echo anything...

    This is definitely an error in my coding... All the right sql fields to allow the script to work are there, etc..

    Thanks a lot :)
    Chuckun

    EDIT: I HAVE RESOLVED THIS ISSUE.
     
    Chuckun, Apr 11, 2009 IP
  2. eamiro

    eamiro Well-Known Member

    Messages:
    274
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #2
    I think you should remove the semicolons from the end of MySQL queries, and also replace `plays` = `plays` +1 by $plays++
     
    eamiro, Apr 11, 2009 IP
  3. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #3
    I took a completely different approach, it's all good :)

    thanks for the advice though, appreciated either way :)
     
    Chuckun, Apr 11, 2009 IP
  4. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Another time, use mysql_error(); after your query... It does often give you a clue on what you've made wrong.

    mysql_query(......)or die(mysql_error());
     
    elias_sorensen, Apr 11, 2009 IP
    Chuckun likes this.