Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP/MySQL-Can';不要插入带撇号的内容_Php_Mysql - Fatal编程技术网

PHP/MySQL-Can';不要插入带撇号的内容

PHP/MySQL-Can';不要插入带撇号的内容,php,mysql,Php,Mysql,我已经试了好几个小时,试图在数据库中插入一个带撇号的简单标题。。。但这很简单,我不想工作 我一直在使用php函数(如下所示),它过去也可以工作。。。但在这种情况下,它根本不起作用 我有以下资料: $GameArray = mysql_fetch_array($QGame); $FixTitle = PHP_slashes($GameArray['Title']); // should retrive "Assassin's Creed IV" 但它不起作用。我不明白为什么。如果我发布一些带有撇

我已经试了好几个小时,试图在数据库中插入一个带撇号的简单标题。。。但这很简单,我不想工作

我一直在使用php函数(如下所示),它过去也可以工作。。。但在这种情况下,它根本不起作用

我有以下资料:

$GameArray = mysql_fetch_array($QGame);
$FixTitle = PHP_slashes($GameArray['Title']); // should retrive "Assassin's Creed IV"
但它不起作用。我不明白为什么。如果我发布一些带有撇号的内容,并像这样做:

PHP_slashes($_POST['content_with_apostrophe']);
它起作用了

下面是供参考的
PHP\u slashes()
函数

function PHP_slashes($string,$type='add')
{
    if ($type == 'add')
    {
        if (get_magic_quotes_gpc())
        {
            return $string;
        }
        else
        {
            if (function_exists('addslashes'))
            {
                return addslashes($string);
            }
            else
            {
                return mysql_real_escape_string($string);
            }
        }
    }
    else if ($type == 'strip')
    {
        return stripslashes($string);
    }
    else
    {
        die('error in PHP_slashes (mixed,add | strip)');
    }
}

停止使用mysql函数。它们已经过时了。切换到mysqli或PDO,使用带有占位符的准备好的语句,这个问题基本上就解决了。此外,addslashes从来都不是SQL服务转义数据的安全方法。就像用蚊帐当避孕套一样。。。毫无意义。这真是一次可怕的逃跑。您应该关闭magic\u quotes并使用
mysql\u real\u escape\u string()
。然后使用
mysqli.*
而不是
mysql.*
,但那是。你在插入数据库后要逃跑吗?@Waleed Khan-我从数据库中得到一个标题。。。然后尝试将其插入另一个表中。我认为您可以使用mysqli和prepared语句,它们将处理所有转义。。。