douluoxiao2286 2013-03-18 13:17
浏览 20
已采纳

PHP如何编码(转义)@,用于电子邮件验证?

I'm getting this error:

Error Number: 1064 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 '@gmail.com' at line 1

Here's the code:

$email = $this->input->post('email');

                $checkEmail = $this->crud_model->retrieve_where('employee', 'email', 'email', $email);

crud_model:

function retrieve_where($table, $table_id, $table_name, $value) {
        $table = $this->db->query('Select * FROM ' . $table . ' Where ' . $table_id . ' = ' . $value);
        $records = array();
        foreach ($table->result() as $row) {
            $records[] = $row->$table_name;
        }
        return $records;
    }
  • 写回答

1条回答 默认 最新

  • duan117890 2013-03-18 13:26
    关注

    The query that you try to execute is:

    SELECT * FROM Email WHERE Email = email@email.com

    Email is in this case a string, and a string needs to be quoted.

    function retrieve_where($table, $table_id, $table_name, $value) {
        $table = $this->db->query("Select * FROM " . mysql_real_escape_string($table) . " Where " . mysql_real_escape_string($table_id) . " = '" . mysql_real_escape_string($value) ."'");
        $records = array();
        foreach ($table->result() as $row) {
            $records[] = $row->$table_name;
        }
        return $records;
    }
    

    Dont forget to escape your query with mysql_real_escape_string(). It will protect you against injections.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解