-1

为什么这样做呢?

代码:

<?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 个字符处被截断。我错过了什么愚蠢的东西吗?看起来我的查询语法是正确的......

4

1 回答 1

4

The problem is because, you have a reserved keyword, unescaped.

$result = $db_con3->query("INSERT INTO gdrive_links (`evalid`, `userid`, `url`, `desc`) VALUES ('$evalid', '$id', '$url', '$desc')");

You need to escape them using backticks, this way. desc is a reserved keyword in MySQL. Escape them like above.

于 2013-05-27T02:12:39.620 回答