Php MYSQL语句回显不正确
我有以下sql语句Php MYSQL语句回显不正确,php,mysql,Php,Mysql,我有以下sql语句 $sql = "select tableid, comment, ID, description from reservations where uniqueid = '" . $reservationid . "'"; $reservationid通过POST表单传递。在另一个页面上,一个选择了不同字段的非常相似的语句似乎可以正常工作。但是当我回显页面上的sql语句时,我得到 select tableid, comment, ID, descriptio
$sql = "select tableid, comment, ID, description from reservations
where uniqueid = '" . $reservationid . "'";
$reservationid通过POST表单传递。在另一个页面上,一个选择了不同字段的非常相似的语句似乎可以正常工作。但是当我回显页面上的sql语句时,我得到
select tableid, comment, ID, description
from reservations
where uniqueid = '51e5f949c1828'
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
从保留中选择表格ID、注释、ID、说明
其中uniqueid='51e5f949c1828使用sprintf()-对于组合字符串之类的事情,这是更好的方法。我认为单引号和双引号混淆了
$sql = "select tableid, comment, ID, description from reservations where uniqueid = "' . $reservationid . '"";
看来你的表格有错误。发送的数据没有正确完成,因此表单html的一部分也随之发送。如果你不发布你是如何发送数据的,我真的很难说。
您必须更正此错误才能使代码正常工作
您提交的PHP没有问题,但是它很容易成为SQL注入攻击的目标,所以最好使用sprintf。
但是当我回显页面上的sql语句时,我得到
select tableid, comment, ID, description
from reservations
where uniqueid = '51e5f949c1828'
select tableid, comment, ID, description from reservations where uniqueid = <'51e5f949c1828
从保留中选择tableid、comment、ID、description,其中uniqueid=您也可以这样进行查询
$sql = "select tableid, comment, ID, description
from reservations where uniqueid = '$reservationid'";
或者干脆
$sql = "select tableid, comment, ID, description
from reservations where uniqueid = $reservationid ";
你能发布示例代码吗?毕竟,你应该使用准备好的语句。发布你的代码。sql中没有错误。您可能没有在表单中的某个位置关闭双引号或单引号。请尝试使用trim($reservationid)
您是正确的!当我回显变量时,浏览器删除了一个格式的零散标记。我将采取措施解决sql注入问题。