【问题标题】:Inserting embed code in database PHP issue在数据库PHP问题中插入嵌入代码
【发布时间】:2011-05-03 03:53:06
【问题描述】:

嘿,我正在尝试在我的数据库中插入一个嵌入代码,它给了我这个错误

Error adding new data: 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 'movie.php?id=6001', 
            type = 'stream', 
            embed = '<object width=\"500\" he' at line 1

现在这是我正在使用的代码:

            $sql = "INSERT INTO videos SET 
            title = '".mysql_escape_string($title)."', 
            urltitle = '".slug(mysql_escape_string($title))."', 
            description = '',
            category = 'streams', 
            first_img = '".mysql_escape_string($imgurl)."', 
            o_url = 'http://watchnewfilms.com/'".mysql_escape_string($thisUrl)."', 
            type = 'stream', 
            embed = '".mysql_escape_string($embed)."', 
            last_updated = '".date("Y-m-d")."', 
            date_added = '".date("Y-m-d")."'";

有人发现有什么问题吗?

谢谢!

【问题讨论】:

    标签: php sql insert embed


    【解决方案1】:

    你应该使用mysql_real_escape_string()

    并且您应该将其应用于整个值,以获得完全的安全性和更好的可读性。

    在你的情况下,你在这里有一个额外的'

        o_url = 'http://watchnewfilms.com/'".mysql_escape_string($thisUrl)."', 
        ----------------------------------^
    

    【讨论】:

    • 哇,谢谢指出!还有mysql真正的转义字符串和mysql的转义字符串有什么区别?
    • @Belgin mysql_real_escape_string() 将使用实时数据库连接,并返回关于该连接字符集的转义结果。 mysql_escape_string()deprecated
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    相关资源
    最近更新 更多