插入查询期间截断字符串 [英] String cutting off during insert query

查看:93
本文介绍了插入查询期间截断字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要这样做?

代码:

<?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个字符处被截断.我想念一些愚蠢的东西吗?看来我的查询语法是正确的...

So the string is fine before and after the query string, but in the query it's being cut off at the 49th character. Am I missing something dumb? It looks like my query syntax is correct...

推荐答案

问题是因为您有

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')");

您需要以这种方式使用反引号将其转义. desc是MySQL中的保留关键字.像上面那样逃避它们.

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

这篇关于插入查询期间截断字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆