Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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 在下面的代码中,我应该在哪里使用转义函数?_Php_Codeigniter - Fatal编程技术网

Php 在下面的代码中,我应该在哪里使用转义函数?

Php 在下面的代码中,我应该在哪里使用转义函数?,php,codeigniter,Php,Codeigniter,我应该如何在下面的代码中使用转义函数 public function Add_video() { $Game_type = $_POST['Game']; $Video_type = $_POST['video_type']; $Url = $_POST['url']; $Url = mysql_escape_string($Url); // Video url $Data = array( '

我应该如何在下面的代码中使用转义函数

public function Add_video()
{
    $Game_type  = $_POST['Game'];
    $Video_type = $_POST['video_type'];
    $Url        = $_POST['url'];
    $Url        = mysql_escape_string($Url); // Video url 

    $Data       = array(
        'Game_type' => $Game_type,
        'Video_type' => $Video_type,
        'Video_url' => $Url
    );

    $this->db->insert('videos', $Data);
}

对于任何post或get请求,请使用Codeigniter的本机

请参阅下面的代码

public function Add_video()
{
    $Game_type  = $this->input->post('Game');
    $Video_type = $this->input->post('video_type');
    $Url        = $this->input->post('url');
    //$Url        = mysql_escape_string($Url); // Video url 

    $data       = array(
        'Game_type' => $Game_type,
        'Video_type' => $Video_type,
        'Video_url' => $Url
    );

    $this->db->insert('videos', $data);
}
或者直接创建阵列:

 $data       = array(
            'Game_type' => $this->input->post('Game'),
            'Video_type' => $this->input->post('video_type'),
            'Video_url' => $this->input->post('url'),
        );

我建议您不要在第一个字母上使用大写字母,例如:“game”而不是“game”

如果您使用Codeigniter,您的查询将自动转义,但在我的数据库中,“”被替换为<和>.。尝试使用urlencode()-稍后将在家中发布一个示例谢谢您考虑我。我找到了解决办法。只需使用htmlspecialchars\u decode()函数即可