The following code doesn't work. $query is fine, but $query2 doesn't seem to work. Does anyone know why?

$name = $_SESSION['username'];

$query = mysql_query("SELECT * FROM players WHERE username ='.$name.'") or die(mysql_error());

$query2 = mysql_fetch_object($query);

    Hi,

    the SELECT query doesn't look ok to me. I think it should look like

    "SELECT * FROM players WHERE username ='".$name."'"
    

    The original query will hardly return anything because it searches for records where username='.$name.' including the periods.

    So the fetch_object command returns nothing.

    the next step after executing the query could look like

    if ($objRow = mysql_fetch_object($query)) {
      echo "Name: ".$objRow->username."<br>\n";
    } else {
      echo "No user found with username: ".$name."<br>\n";
    }
    

    Thomas

      You were right about the SELECT query. Thanks.

      This is one of the things that annoys me about PHP; the niggling little details like this that casuse such problems.

        Write a Reply...