gpt4 book ai didi

php - 没有显示 mysql select all 的结果

转载 作者:太空宇宙 更新时间:2023-11-03 10:24:14 25 4
gpt4 key购买 nike

大家好,我正在尝试向所有用户展示 pokemon 是表 belongsto = 这里的用户名是我的代码我在这上面有一个很好的连接

     // 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'];

}

我已经将用户名打印成红色并且用户名在用户名 session 中。我想我可能会遗漏一个 ' 或我在查询末尾添加的内容或 mysql,但随后页面会毫无错误地死掉

最佳答案

您没有运行查询并且其中有错误。而且您不会转义进入查询的字符串。代码的正确版本是

// 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'];
}

关于php - 没有显示 mysql select all 的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7625942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com