Mysql Query issue in php please help?

Discussion in 'PHP' started by mokimofiki, May 18, 2009.

  1. #1
    Not sure what the isue is but when i use the following code nothing is displayed:

    <?php
    $result = mysql_query("SELECT * FROM playerstats WHERE name='$playername'");
    while($row = mysql_fetch_array($result)) 
        {
        echo "<table border=\"0\" width=\"800\" cellpadding=\"0\" cellspacing=\"0\">";
        echo "<tr>";
        echo "<td>Health: " . $row['health'] . "/100</td>";
        echo "<td>Energy: " . $row['energy'] . "/10</td>";
        echo "<td>Stamina: " . $row['stamina'] . "/5</td>";
        echo "<td>Fame: " . $row['fame'] . "</td>";
        echo "<td>Cash: $" . $row['gold'] . "</td>";
        echo "<td>Experience: " . $row['experience'] . "/500</td>";
        echo "<td>Level: " . $row['level'] . "</td>";
        echo "</tr>";
        echo "</table>";
        }
    ?>
    Code (markup):
    It seems the problem is with the:

    $result = mysql_query("SELECT * FROM playerstats WHERE name='$playername'");
    while($row = mysql_fetch_array($result))

    Because if take that out the table will display (without db info of course) but with those lines nothing shows at all.

    Any help would be appriciated thank you :)
     
    mokimofiki, May 18, 2009 IP
  2. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #2
    $result = mysql_query("SELECT * FROM playerstats WHERE name='$playername'") or die(mysql_error());
    PHP:
    Does it return any error? Is the $playername safe?
     
    Sky AK47, May 18, 2009 IP
    mokimofiki likes this.
  3. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #3
    No error ... it just doesn't display anything at all

    $playername = "test"

    and there is a name called test in the playerstats table
     
    mokimofiki, May 18, 2009 IP
  4. mussolinihitler

    mussolinihitler Peon

    Messages:
    258
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    please replace the WHERE name='$playername' with WHERE name='test' and tell me if it shows anything
     
    mussolinihitler, May 18, 2009 IP
  5. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #5
    it seems to work fine that way ... I just checked the variable and it seems i had 2 = signs when saving the member name .... thank you for your help it was a stupid overlook on my part

    Thank you
     
    mokimofiki, May 18, 2009 IP
  6. mussolinihitler

    mussolinihitler Peon

    Messages:
    258
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ok........glad to hear its working for u....:)
     
    mussolinihitler, May 18, 2009 IP
    mokimofiki likes this.