gpt4 book ai didi

php mysql 通过变量搜索?

转载 作者:行者123 更新时间:2023-11-29 14:15:20 25 4
gpt4 key购买 nike

请帮助我如何从 mysql 中检索具有变量的数据我的 sql 查询..我的 php 代码是

$status=$_GET['status'];
$query="SELECT * FROM students WHERE status='$status' ";

当我运行 mysql 生成的查询时

 unknown column 'Lead'

其中 Lead 是 $status 的值。我尝试过\'$status\' , '{$status}' 但同样的错误..请帮助我,我从昨天开始就在努力,但没有找到解决方案。我尝试了 mysql_real_escape_string() 但同样的错误..可能是我使用了错误的语法。

  $query="SELECT * FROM students WHERE status=".mysql_real_escape_string($status);

提前致谢......

最佳答案

$status=$_GET['status'];
$query="SELECT * FROM students WHERE status='".$status."'";

转义是个好主意,但我认为 mysql_escape_string 已被弃用,并且不鼓励使用它,您应该始终使用 mysql_real_escape_string

关于php mysql 通过变量搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12789419/

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