我有以下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/