php - 检查 PHP 中的查询字符串值

标签 php mysql query-string

http://localhost/?area=characters&name=Michal+Stroganof



$result = mysql_query("SELECT * from players WHERE name = '$_GET[name]'");

while ($row = mysql_fetch_assoc($result)) {

    echo "Name: " .$row['name']. "<br>";
    echo "Level: " .$row['level']. "<br>";

}

这是我的characters.php的全部代码

如果 get 变量“名称”未包含在 URL 中,我想显示一个搜索表玩家的搜索表单。我该怎么做?

最佳答案

您的意思是像这样更改您的 SQL 字符串吗?

$sql = 'SELECT * from players';
if (isset($_GET['name'])) {
    $safename = mysql_real_escape_string($_GET['name']);
    $sql .= " WHERE name='$safename'";
}
$result = mysql_query($sql);

一定要清理你的 SQL!

关于php - 检查 PHP 中的查询字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1745389/

相关文章:

php - 如何使用准备好的PDO语句设置ORDER BY参数?

php - 在 "created by"框中为每个产品和优惠券等添加 "post_submitbox_misc_actions"

mysql - 如何根据标签获取相似对象

java - CPU使用率峰值玩框架java mysql

mysql - 提高 Solr 和 MySQL 对的性能(使用 JPA 通过 "WHERE IN"连接)

ruby-on-rails - 当存在相同的键时,Rails 中的查询字符串操作

jquery - 有没有办法获取 jquery jqGrid 的 "full"URL 来维护过滤器的状态?

php - 从复选框列表 yii2 中获取值

php - codeigniter:将数组从 Controller 传递到 View

node.js - Express.js 是否遵守 RFC-3986 的查询字符串?