php - MYSQL 语句未正确回显

标签 php mysql

我有以下sql语句..

$sql = "select tableid, comment, ID, description from reservations 
        where uniqueid = '" . $reservationid . "'";

$reservationid 通过 POST 表单传递。选择不同字段的非常相似的语句似乎在另一个页面上运行良好。但是当我在页面上回显 sql 语句时,我得到

select tableid, comment, ID, description 
from reservations 
where uniqueid = '51e5f949c1828'

似乎跳过了最后的单引号

我也尝试过

$sql = "select tableid, comment, ID, description from reservations 
        where uniqueid = '$reservationid'";

结果相同。如果我查看页面源代码,我无法理解为什么我会看到这个..

select tableid, comment, ID, description from reservations 
where uniqueid = '51e5f949c1828</form

那个流浪者到底在哪里</form>部分来自?

最佳答案

But when i echo the sql statement on the page i get

select tableid, comment, ID, description from reservations where uniqueid = <'51e5f949c1828 

如果您“回显”到浏览器窗口,则浏览器很有可能会默默地删除 </form>从显示屏上。我的赌注是,如果您在显示查询时查看页面的源代码,您将看到 ... where uniqueid = '51e5f949c1828</form>也是如此。

正如你所确定的$reservationid包含您期望的内容吗?

您能否显示更多代码。喜欢你的 html 表单吗?那里可能存在格式错误的 html 和/或未闭合的引号。

<小时/>

顺便说一句,您永远不应该在查询中直接注入(inject)来自不受信任源的变量。这导致 SQL injection .

关于php - MYSQL 语句未正确回显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17992117/

相关文章:

mysql - 代表特定日期字段的周报

php - 检查用户名是否存在,然后我要更新

php - 将 php 数组分配给 javascript 数组

php - wordpress 网站上的缩略图问题?

php - 我的 cookie 仅在设置它们的 PHP 页面上可用,这正常吗?

php - 查询生成器调用非对象上的成员函数 createQueryBuilder()

MySQL 根据 DATE 更新列的值

php - 编辑记录 PHP 表单

php - Laravel 架构生成器 |独特的、区分大小写的列

mysql - 在目录数据库中具有两个不同类别 ID 的产品 ID