开发者

No results showing for mysql select all

Hello guys i am trying to show all the users pokemon were the table belongsto = there username here is my code i have a connect on top of this has well

     // Get all the data from the "example" table
$result = "SELECT * FROM user_pokemon WHERE
    belongsto='".$_SESSION['username']."'
AND (slot='0')'"; 
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table

    echo $row['pokemon'];

    echo $row['id'];

} 

i have print red the u开发者_运维问答sername and there username is in the username session . i think i mite be missing a ' or something i add or mysql at the end of the query but then the pages dies with no error


You are not running the query and have an error in it. And you're not escaping strings going into query. A proper version of the code would be

// escape a string going to query.
$username = mysql_real_escape_string($_SESSION['username']);
// create a query
$sql = "SELECT * FROM user_pokemon WHERE belongsto='$username' AND slot=0"; 
// run a query and output possible error for debugging purposes.
$res = mysql_query($sql) or trigger_error(mysql_error()." in ".$sql);
// keep getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
  echo $row['pokemon'];
  echo $row['id'];
} 


It appears to me that the final query would be:

SELECT * FROM user_pokemon WHERE belongsto='NAME' AND (slot='0')'

where NAME is the name you pass in. If that is the case, there is an extra single quote at the end. I presume you are getting a SQL error?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜