php - 无法检查 mysql 中的值是否有 addslashes 值

标签 php mysql codeigniter

当我提交表单时,我已将数据存储在数据库中,并添加了斜杠。

我使用如下函数存储值

addslashes(trim($data[1]));

我想检查该表中的现有记录,但当它具有像这样的值时它不起作用

Regional Sales Director - Americas\'

它检查表中的现有值,没有那些斜杠

\'

我的查询是

$query = $this->db->query("select * from tbl_contacts where contact_name='".$name."' and contact_company='".$company."' and contact_designation='".$designation."'");
$result1 = $query->result();

最佳答案

我不确定我是否应该回答这个问题,但我觉得我应该回答,因为你所做的事情在很多方面都是错误的......

如果你想插入数据,你永远不应该做这样的事情 - 特别是如果你使用可以为你完成这项工作的框架......

首先你必须了解Codeigniter如何插入数据

使用查询生成器

插入数据的示例是

$arrData = [
    'contact_name' => $this->input->post('contact_name'),
    'contact_company' => $this->input->post('contact_company')
];

$this->db->insert('tbl_contacts', $arrData);

please read carefully the section in the CI Documentation here

你的选择查询是一场灾难,因为你没有保护任何东西 - 正如亚历克斯在评论中所说的那样,你对任何类型的攻击都持开放态度

相反,您应该尝试以下操作:

$query = $this->db
    ->select('*')
    ->from('tbl_contacts')
    ->where('contact_name', $name)
    ->where('conatct_company', $company)
    ->where('contact_designation', $designation)
    ->get();

$result1 = $query->result();    

此外,请阅读文档,下面是一些必填链接

  1. Form Validation
  2. Security Class
  3. Input Class
  4. Query Builder Class

关于php - 无法检查 mysql 中的值是否有 addslashes 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47451647/

相关文章:

javascript - 使用隐藏输入检索用户数据是否安全?

javascript - php 文件到 php 数组到 js 数组 - 作为数组的数组

php - 如何强制下载文件?

mysql - 按特定条件订购

php - 使用 PHP 和 MYSQL 的动态下拉列表

php - 试图获取非对象代码点火器的属性

php - Codeigniter $this->session->set_userdata() 工作不正常

php - Prestashop blocklayered + 无限滚动问题

mysql外键仅引用复合主键的一部分

php - 使用 session 数据用户 ID 进行条件检查在 Codeigniter 中不起作用的情况