【发布时间】:2013-05-27 02:03:15
【问题描述】:
为什么要这样做?
代码:
<?php
if (isset($_POST['sourceInsert'])) {
$url = $db_con3->real_escape_string($_POST['url']);
$desc = $db_con3->real_escape_string($_POST['desc']);
echo '$urlbefore is ' . $url . '<br />'; ///for troubleshooting
$result = $db_con3->query("INSERT INTO gdrive_links (evalid, userid, url, desc) VALUES ('$evalid', '$id', '$url', '$desc')");
echo '$urlafter is ' . $url . '<br />'; ///For troubleshooting
echo $db_con3->error; ///For troubleshooting
}
?>
HTML 输出:
$urlbefore is https://docs.google.com/file/d/0B0tcjQ3FxlB6dWlMTkNQVjBwVDA/edit?usp=sharing
$urlafter is https://docs.google.com/file/d/0B0tcjQ3FxlB6dWlMTkNQVjBwVDA/edit?usp=sharing
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc) VALUES ('1284017', '1', 'https://docs.google.com/file/d/0B0tcjQ3FxlB6dWlMT' at line 1
所以字符串在查询字符串之前和之后都很好,但是在查询中它在第 49 个字符处被截断。我错过了什么愚蠢的东西吗?看来我的查询语法是正确的...
【问题讨论】:
-
你有
(evalid, userid, url, desc) VALUES ('$evalid', '$id', '$url', '$desc'),不应该是(evalid, userid, url, desc) VALUES ('$evalid', '$userid', '$url', '$desc')吗? -
desc是 mysql 关键字...重命名为任何其他 -
不,这个表的userid是用户的$id。
-
自我注意...不要使用 desc 作为字段名,永远...:)
-
@Rich701 你可以,但在转义之后。 :)